-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-146582: Improve syntax error for non-case statement inside match statement
#146583
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1503,6 +1503,7 @@ invalid_case_block: | |
| | "case" patterns guard? NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") } | ||
| | a="case" patterns guard? ':' NEWLINE !INDENT { | ||
| RAISE_INDENTATION_ERROR("expected an indented block after 'case' statement on line %d", a->lineno) } | ||
| | !"case" { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("expected 'case' statement inside 'match' statement") } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless I'm missing something, is this still incomplete for invalid statements that start with soft-keyword For example with compile("match 1:\n case = 1\n", "<repro>", "exec")
compile("match 1:\n case += 1\n", "<repro>", "exec")
compile("match 1:\n case, x = 1, 2\n", "<repro>", "exec")you get: So the new diagnostic still doesn't seem to catch these
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm, possibly? It occurred that me that this wouldn't catch cases like this, but I figured that this would be tricky to do right and only represents a vanishingly small set of statements in practice, so I didn't give it much thought. Do you think it's worth trying to catch these too? I'd worry that a rule that matches these cases would also run the risk of matching an actual malformed |
||
| invalid_as_pattern: | ||
| | or_pattern 'as' a="_" { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use '_' as a target") } | ||
| | or_pattern 'as' a=expression { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Improve :exc:`SyntaxError` message when a statement other than a | ||
| :keyword:`case` statement appears inside a :keyword:`match` statement. | ||
| Patch by Brian Schubert. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.