chapel icon indicating copy to clipboard operation
chapel copied to clipboard

Disallow tuple expressions with underscores in non-declaration contexts

Open DanilaFe opened this issue 9 months ago • 0 comments

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:

  1. Allow _ to make it from the parser to the AST, even in non-declaration contexts like var x = _.
  2. Add a post-parse check to detect _ and warn about it, except in declaration sites
  3. Make that post-parse check have a nicer error message :)

DanilaFe avatar May 07 '24 00:05 DanilaFe