-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expect indented case block instead of match stmt (#11033)
## Summary This PR adds a new `Clause::Case` and uses it to parse the body of a `case` block. Earlier, it was using `Match` which would give an incorrect error message like: ``` | 1 | match subject: 2 | case 1: 3 | case 2: ... | ^^^^ Syntax Error: Expected an indented block after `match` statement | ``` ## Test Plan Add test case and update the snapshot.
- Loading branch information
1 parent
06c248a
commit 9bb23b0
Showing
3 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
crates/ruff_python_parser/resources/inline/err/case_expect_indented_block.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
match subject: | ||
case 1: | ||
case 2: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
crates/ruff_python_parser/tests/snapshots/invalid_syntax@case_expect_indented_block.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
source: crates/ruff_python_parser/tests/fixtures.rs | ||
input_file: crates/ruff_python_parser/resources/inline/err/case_expect_indented_block.py | ||
--- | ||
## AST | ||
|
||
``` | ||
Module( | ||
ModModule { | ||
range: 0..43, | ||
body: [ | ||
Match( | ||
StmtMatch { | ||
range: 0..42, | ||
subject: Name( | ||
ExprName { | ||
range: 6..13, | ||
id: "subject", | ||
ctx: Load, | ||
}, | ||
), | ||
cases: [ | ||
MatchCase { | ||
range: 19..26, | ||
pattern: MatchValue( | ||
PatternMatchValue { | ||
range: 24..25, | ||
value: NumberLiteral( | ||
ExprNumberLiteral { | ||
range: 24..25, | ||
value: Int( | ||
1, | ||
), | ||
}, | ||
), | ||
}, | ||
), | ||
guard: None, | ||
body: [], | ||
}, | ||
MatchCase { | ||
range: 31..42, | ||
pattern: MatchValue( | ||
PatternMatchValue { | ||
range: 36..37, | ||
value: NumberLiteral( | ||
ExprNumberLiteral { | ||
range: 36..37, | ||
value: Int( | ||
2, | ||
), | ||
}, | ||
), | ||
}, | ||
), | ||
guard: None, | ||
body: [ | ||
Expr( | ||
StmtExpr { | ||
range: 39..42, | ||
value: EllipsisLiteral( | ||
ExprEllipsisLiteral { | ||
range: 39..42, | ||
}, | ||
), | ||
}, | ||
), | ||
], | ||
}, | ||
], | ||
}, | ||
), | ||
], | ||
}, | ||
) | ||
``` | ||
## Errors | ||
|
||
| | ||
1 | match subject: | ||
2 | case 1: | ||
3 | case 2: ... | ||
| ^^^^ Syntax Error: Expected an indented block after `case` block | ||
| |