ponyc
ponyc copied to clipboard
Unhelpful error message for variable capture in match expressions
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".
We should definitely do this. Not a good message at all.
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.