ponyc icon indicating copy to clipboard operation
ponyc copied to clipboard

Unhelpful error message for variable capture in match expressions

Open Theodus opened this issue 8 years ago • 2 comments

When a let or var is omitted from a variable capture in a match expression, as shown by this code:

actor Main
  new create(env: Env) =>
    let a: (I64 | None) = 7

    env.out.print(match a
      | n: I64 => n.string()
      else ""
    end)

the compiler gives this error:

Error:
/home/theodus/dev/wat/main.pony:6:19: syntax error: unterminated match expression
    env.out.print(match a
                  ^
    Info:
    /home/theodus/dev/wat/main.pony:7:10: expected terminating end before here
          | n: I64 => n.string()
             ^

It should probably be changed to something like "variable capture requires let or var declaration".

Theodus avatar Dec 21 '16 18:12 Theodus

We should definitely do this. Not a good message at all.

SeanTAllen avatar Dec 21 '16 20:12 SeanTAllen

For whoever is interested in doing this - this will require expanding the parser to allow the invalid syntax, then checking for and disallowing the invalid syntax during the syntax.c compiler pass. This is our general strategy for adding more helpful error messages to invalid syntax.

jemc avatar Dec 21 '16 20:12 jemc