#2613 Misleading compiler message

LightDye Wed 28 Jun

I have a class of this form:

class MyClass
  const Func myFunc := |Foo foo, Bar bar| {
    // do stuff

  MyType myVar := MyType()

  Void main() {
    // do more stuff

In this example, the class called Bar belongs to another pod but I forgot to add

using myOtherPod

so the compiler couldn't figure it out, but the error message it gave on line 3 was quite misleading as it only said:

Expected expression, not '|'

(Thanks Steve for pointing out what the actual error was: see StackOverflow)

If I removed the definition of myFunc altogether and MyType was also on the non-referenced pod, the compiler error is far more obvious:

Unknown type 'MyType'

Can the first compilation error message be improved, please?

brian Wed 4 Oct

This is a side effect of the parser needing to know whether an identifier is a known type. Its a fairly deep requirement of how the parser design works and is tied up into lots of complexity with deciding how to parse closures with and without type parameters. I spend a little time seeing if can get an exact error message such as "Unknown type", but it would require serious redesign of the parser. So as simple solution I fixed it to report a more meaningful error message when it knows that pipe should be a closure:

Invalid closure expression (check types)

Login or Signup to reply.