gracelang / minigrace

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

Misleading error message with dotted class names #216

Closed KimBruce closed 8 years ago

KimBruce commented 8 years ago

If a program contains a "dotted" class name, the system returns a very unhelpful error message:

CheckerFailure: no return type given to declaration of method 'asString'. in "Vehicle" (line 9, column 1)

where line 9 is:

class vehicle.startAt (startPt: Point) image(carURL: String) going (speed: Number)
    carSize (carWidth: Number, carHeight: Number)
    laneEnds (laneLeft: Number, laneRight: Number)
    frog (theFrog: fr.Frog) on (canvas: DrawingCanvas) -> Animated {

Obviously, no indication of an "asString" method anywhere!

Note the system used not to complain about dotted class names at all, so this is an improvement, but it is very misleading!

apblack commented 8 years ago

Note that the message says "CheckerFailure". I think that it is coming from your checker, probably the requiretypes checker.

Yes, dotted classes should be removed soon.

KimBruce commented 8 years ago

Yes, I can see where in requiredTypes the message is generated, I just have no idea how it got that from walking the tree.

Maybe it's best to just wait until the dotted classes are removed and then see if the problem still shows up in that way. (I am appreciating getting the error as it helps me find those places that have not yet been updated.)

apblack commented 8 years ago

A dotted class introduces two object constructors. In the inner one, the programmer can write their own asString method. For the outer one, the parser generates an asString method that answers "foo class", where "foo" is the name before the dot. That method doesn't have a declared return type, so you get the message.

A possible fix would be to change requiredTypes to recognize this case and not generate a message.