chapel
chapel copied to clipboard
Disallow tuple expressions with underscores in non-declaration contexts
Today, you can write the following:
var x = (_, );
Which parses fine but gives the following, relatively confusing error message:
loop.chpl:1: In module 'loop':
loop.chpl:1: error: 'chpl__tuple_blank' undeclared (first use this function)
This is because currently, we use the same production rules to match both the left and right hand sites of declarations (so, the e
in for e in
is parsed the same way as var x = e
). Since we need tuple expressions on the left -- to allow value-ignoring assignments -- we need the _
. To improve the situation w.r.t. https://github.com/chapel-lang/chapel/issues/25001, I think the play is to do the following:
- Allow
_
to make it from the parser to the AST, even in non-declaration contexts likevar x = _
. - Add a post-parse check to detect
_
and warn about it, except in declaration sites - Make that post-parse check have a nicer error message :)