#1407 Better Error Messages

kaushik Wed 2 Feb 2011

Yesterday I was teaching fantom to a set of people and these are some places where they din't seem to "get" the error from the message.

1) When the Type name is not found during list creation

a := String[,]

Here an error message like "Unknown class" would have helped while the current error message is "Expected expression, not , "

2) When type name is not found in declaration of nullable type

String?  a := null

Here again the error message is " Expected :, not := "

3) Using "," in the serialization syntax to create object

class Tests{
    Int? a
    Int? b
}
t := Tests{a = 1, b =1}

Error: Unknown method CLASS::Tests.add.

4) Misplaced :=

Try setting an instance variable using ":="

this.instance := 1

Error: "Expected expression statement"

brian Wed 2 Feb 2011

Promoted to ticket #1407 and assigned to brian

I might be able to fix some of those. Although some of those are problems where the identifier isn't a proper type, so it is assumed to be a variable.

brian Wed 2 Mar 2011

Ticket resolved in 1.0.58

I was able to improve the error messages for all four cases:

fansh> a := BadType[,]
ERROR(10): Unknown type 'BadType' for list literal

fansh> BadType? a := null
ERROR(5): Unknown type 'BadType' for local declaration

fansh> this.instance := 1
ERROR(5): Left hand side of ':=' must be identifier

script> Foo { a = 2, b = 3 }
play.fan(8,18): No comma operator method found: 'play_0::Foo.add'

developpef Wed 12 Sep 2012

Hello,

I am a Java developer, new to fantom. Using f4 editor it seems that I faced quite the same issue. Here is my code :

static Void call(String param := "vide") { echo(param); }

This shows a good error message : "Unknown type String". But this syntax :

mymap := [1:"test",2:"vfd"]; mymap.each |String v, Int k| { echo("cle:$k, valeur:$v") }

Displays a weird message : "Expected expression statement".

Hope this will help you improve editor code analysis.

DanielFath Mon 24 Sep 2012

I think this needs to be reopened. Good error messages should be obligatory to any language.

Login or Signup to reply.