Skip to content

Commit 9f9ba02

Browse files
committed
Fix end location of nodes containing body
1 parent 2edd0d2 commit 9f9ba02

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

compiler/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,

compiler/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

compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_class.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)