mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-01 08:07:31 +00:00
Fix range of unparenthesized tuple subject in match statement (#8101)
## Summary This was just a bug in the parser ranges, probably since it was initially implemented. Given `match n % 3, n % 5: ...`, the "subject" (i.e., the tuple of two binary operators) was using the entire range of the `match` statement. Closes https://github.com/astral-sh/ruff/issues/8091. ## Test Plan `cargo test`
This commit is contained in:
parent
95702e408f
commit
d6a4283003
7 changed files with 2763 additions and 2369 deletions
|
@ -466,7 +466,7 @@ MatchStatement: ast::Stmt = {
|
|||
}
|
||||
)
|
||||
},
|
||||
<location:@L> "match" <subject:TestOrStarNamedExpr> "," ":" "\n" Indent <cases:MatchCase+> Dedent => {
|
||||
<location:@L> "match" <tuple_location:@L> <subject:TestOrStarNamedExpr> "," <tuple_end_location:@R> ":" "\n" Indent <cases:MatchCase+> Dedent => {
|
||||
let end_location = cases
|
||||
.last()
|
||||
.unwrap()
|
||||
|
@ -476,13 +476,19 @@ MatchStatement: ast::Stmt = {
|
|||
.end();
|
||||
ast::Stmt::Match(
|
||||
ast::StmtMatch {
|
||||
subject: Box::new(subject.into()),
|
||||
subject: Box::new(ast::Expr::Tuple(
|
||||
ast::ExprTuple {
|
||||
elts: vec![subject.into()],
|
||||
ctx: ast::ExprContext::Load,
|
||||
range: (tuple_location..tuple_end_location).into()
|
||||
},
|
||||
)),
|
||||
cases,
|
||||
range: (location..end_location).into()
|
||||
}
|
||||
)
|
||||
},
|
||||
<location:@L> "match" <elts:TwoOrMore<TestOrStarNamedExpr, ",">> ","? ":" "\n" Indent <cases:MatchCase+> Dedent => {
|
||||
<location:@L> "match" <tuple_location:@L> <elts:TwoOrMore<TestOrStarNamedExpr, ",">> ","? <tuple_end_location:@R> ":" "\n" Indent <cases:MatchCase+> Dedent => {
|
||||
let end_location = cases
|
||||
.last()
|
||||
.unwrap()
|
||||
|
@ -497,7 +503,7 @@ MatchStatement: ast::Stmt = {
|
|||
ast::ExprTuple {
|
||||
elts,
|
||||
ctx: ast::ExprContext::Load,
|
||||
range: (location..end_location).into()
|
||||
range: (tuple_location..tuple_end_location).into()
|
||||
},
|
||||
)),
|
||||
cases,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue