Skip to content

Commit 6dba843

Browse files
committed
Fix end location for elif blocks
Since we parse an `elif:` block as an `If` node, its location should include its `orelse` node like it would for an `if:` block. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
1 parent b26365b commit 6dba843

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎parser/python.lalrpop‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ IfStatement: ast::Stmt = {
372372
let x = ast::Stmt {
373373
custom: (),
374374
location: i.0,
375-
end_location: i.4.last().unwrap().end_location,
375+
end_location,
376376
node: ast::StmtKind::If { test: Box::new(i.2), body: i.4, orelse: last },
377377
};
378378
last = vec![x];

‎parser/src/snapshots/rustpython_parser__parser__tests__parse_if_elif_else.snap‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ expression: parse_ast
7979
},
8080
end_location: Some(
8181
Location {
82-
row: 2,
83-
column: 10,
82+
row: 3,
83+
column: 8,
8484
},
8585
),
8686
custom: (),

0 commit comments

Comments
 (0)