Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nicer error message for out-of-place _ #25001

Open
DanilaFe opened this issue May 7, 2024 · 1 comment · May be fixed by #25168
Open

nicer error message for out-of-place _ #25001

DanilaFe opened this issue May 7, 2024 · 1 comment · May be fixed by #25168

Comments

@DanilaFe
Copy link
Contributor

DanilaFe commented May 7, 2024

Today, writing for _ in 1..10 will lead to a generic "syntax error". This is not an ideal error message, but seems like it ought to be easy enough to make it a nice error message. For instance, it would be nice to note that _ can only be used in declaration context like var _ = ... and loop tuple-expressions.

@bradcray
Copy link
Member

bradcray commented May 7, 2024

it would be nice to note that _ can only be used in declaration context like var _ = ...

Note that it's currently a syntax error in this context as well, e.g.

var _ = 42;

gives:

testit.chpl:1: syntax error: near '_'

I believe that today it's only permitted in de-tupling declaration contexts like:

var (first, _) = myTupleExpr;

DanilaFe added a commit that referenced this issue May 7, 2024
Fixes #25000 (what a fun
issue number!).

This PR disallows writing `(_)`, to match the already-disallowed `_`.
Prior to this PR, the following program did not parse:

```Chapel
var x = _;
```

But the following alternate version did:

```Chapel
var x = (_);
```

This was because the parenthesized-expression grammar rule used
`tuple_component`, which allows `_` (`(_, )` can be used to unpack
1-tuples in loops). As a result, this fixes the odd issue in which
writing a loop over `(_)` resulted in an internal error, while `_`
resulted in a normal syntax error.

This raised some follow-up concerns:
1. should we have a nicer error message when a user writes `_` where it
doesn't belong? #25001
2. should we really allow `_` in all tuple expressions? currently we do.
#25002

In the meantime, this PR turns the error in #25000 from an internal
error into a syntax error.

Reviewed by @vasslitvinov -- thanks!

## Testing
- [x] paratest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants