-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Patterns: unhelpful parse errors when case clause const expression is not valid #50996
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
Comments
@stereotype441, please re-assign as needed. |
@scheglov fyi |
This is expected behaviour with patterns enabled. See the spec section "Breaking existing switches", specifically this paragraph:
As the spec mentions, the workaround is to wrap the constant in void f(Object? x) {
switch (x) {
case const (5 * 5):
break;
}
} |
@keertip ok, thanks, I understand now. Unfortunately, improving the parse errors will probably be difficult bug to fix because of architectural limitations of the parser. As currently designed, the parsing logic for patterns and for expressions is entirely separate, and the parser chooses which logic to use after a I'm open to ideas for how to improve this, just trying to set expectations 😃. CC @jensjoha or @johnniwinther in case either of them have ideas for how to improve this situation. |
Would it be possible, at the point where it sees a If we can get a more specific diagnostic, then we can add a fix to wrap it in the |
Seeing Parse errors for this code:
Other const expressions under switch statement in spec.
The text was updated successfully, but these errors were encountered: