Skip to content

Commit 1b7a272

Browse files
committed
Fix end location of nodes containing body
1 parent 3abdc87 commit 1b7a272

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎parser/python.lalrpop‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,10 @@ WithItem: ast::Withitem = {
492492
};
493493

494494
FuncDef: ast::Stmt = {
495-
<decorator_list:Decorator*> <location:@L> <is_async:"async"?> "def" <name:Identifier> <args:Parameters> <r:("->" Test)?> ":" <body:Suite> <end_location:@R> => {
495+
<decorator_list:Decorator*> <location:@L> <is_async:"async"?> "def" <name:Identifier> <args:Parameters> <r:("->" Test)?> ":" <body:Suite> => {
496496
let args = Box::new(args);
497497
let returns = r.map(|x| Box::new(x.1));
498+
let end_location = body.last().unwrap().end_location.unwrap();
498499
let type_comment = None;
499500
let node = if is_async.is_some() {
500501
ast::StmtKind::AsyncFunctionDef { name, args, body, decorator_list, returns, type_comment }
@@ -646,15 +647,16 @@ KwargParameter<ArgType>: Option<Box<ast::Arg>> = {
646647
};
647648

648649
ClassDef: ast::Stmt = {
649-
<decorator_list:Decorator*> <location:@L> "class" <name:Identifier> <a:("(" ArgumentList ")")?> ":" <body:Suite> <end_location:@R> => {
650+
<decorator_list:Decorator*> <location:@L> "class" <name:Identifier> <a:("(" ArgumentList ")")?> ":" <body:Suite> => {
650651
let (bases, keywords) = match a {
651652
Some((_, arg, _)) => (arg.args, arg.keywords),
652653
None => (vec![], vec![]),
653654
};
655+
let end_location = body.last().unwrap().end_location;
654656
ast::Stmt {
655657
custom: (),
656658
location,
657-
end_location: Some(end_location),
659+
end_location,
658660
node: ast::StmtKind::ClassDef {
659661
name,
660662
bases,

‎parser/src/parser.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ class Foo(A, B):
173173
def __init__(self):
174174
pass
175175
def method_with_default(self, arg='default'):
176-
pass";
176+
pass
177+
";
177178
insta::assert_debug_snapshot!(parse_program(source, "<test>").unwrap());
178179
}
179180

‎parser/src/snapshots/rustpython_parser__parser__tests__parse_class.snap‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ expression: "parse_program(source, \"<test>\").unwrap()"
6262
},
6363
end_location: Some(
6464
Location {
65-
row: 4,
66-
column: 1,
65+
row: 3,
66+
column: 6,
6767
},
6868
),
6969
custom: (),

0 commit comments

Comments
 (0)