From 16c1e214d64ff75e41f87b14a82d7ada8951d7fd Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 17 Jan 2023 22:14:24 -0500 Subject: [PATCH] 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 --- compiler/parser/python.lalrpop | 2 +- .../rustpython_parser__parser__tests__parse_if_elif_else.snap | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/parser/python.lalrpop b/compiler/parser/python.lalrpop index 90f4ce258..604a4f966 100644 --- a/compiler/parser/python.lalrpop +++ b/compiler/parser/python.lalrpop @@ -372,7 +372,7 @@ IfStatement: ast::Stmt = { let x = ast::Stmt { custom: (), location: i.0, - end_location: i.4.last().unwrap().end_location, + end_location, node: ast::StmtKind::If { test: Box::new(i.2), body: i.4, orelse: last }, }; last = vec![x]; diff --git a/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_if_elif_else.snap b/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_if_elif_else.snap index 7f493dddf..26bd492b9 100644 --- a/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_if_elif_else.snap +++ b/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_if_elif_else.snap @@ -79,8 +79,8 @@ expression: parse_ast }, end_location: Some( Location { - row: 2, - column: 10, + row: 3, + column: 8, }, ), custom: (),