gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

Receiver of isMe compiled incorrectly #252

Open apblack opened 6 years ago

apblack commented 6 years ago

The file wrongSelfRoom contains

class room {
    def name = "Non-descript room."
    def description = "Nothing to see here. Move along."
}

The file wrongSelf contains

import "wrongSelfRoom" as rooms

class room {
    def name = "Non-descript room."
    def description = "Nothing to see here. Move along."
}

def n = object {
    inherit rooms.room   // if we instead inherit the local 
                         // room, everything is OK
    method ==(other) { 
        self.isMe (other)  // self should be unnecessary.  But without it
                      // the target is compiled as outer.
    }
    method asString { "the northern room" }
}
print (n == n)  // should be true

testBasicDirections

The print statement prints false, unless the request of isMe(other) is changed to self.isMe(other), in which case it works.

If the inherit statment is changed to refer to the local definition of room instead of the one in the rooms module, all is well.

This case came to light while I was attempting to get Steven L. Willoughby's interactive fiction (iFiction) game working in minigrace.

apblack commented 6 years ago

On reflection, I think that the problem is that information about the inherited methods from the imported module is not being propagated to the inheritor.

apblack commented 5 years ago

The gct information for wrongSelfRoom is as follows:

classes:
confidential:
dialect:
 standardGrace
fresh-methods:
 room
fresh:room:
 description
 name
modules:
 collectionsPrelude
 standardGrace
path:
 /Users/black/Downloads/Grace-IDE-Archive-7-19-2018/minigrace_issues/#252_wrongSelfRoom.grace
public:
 room
publicMethodTypes:
 room
types:

Notice that isMe and other inherited methods are not listed as being in the scope of the fresh method room.