Skip to content

Commit 06a815f

Browse files
authored
Merge pull request RustPython#4358 from harupy/fix-slice-location
Fix `Slice` location
2 parents 647d542 + d7f7fd2 commit 06a815f

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

compiler/parser/python.lalrpop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ SubscriptList: ast::Expr = {
10241024

10251025
Subscript: ast::Expr = {
10261026
Test<"all">,
1027-
<e1:Test<"all">?> <location:@L> ":" <e2:Test<"all">?> <e3:SliceOp?> <end_location:@R> => {
1027+
<location:@L> <e1:Test<"all">?> ":" <e2:Test<"all">?> <e3:SliceOp?> <end_location:@R> => {
10281028
let lower = e1.map(Box::new);
10291029
let upper = e2.map(Box::new);
10301030
let step = e3.flatten().map(Box::new);

compiler/parser/src/parser.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,11 @@ class Foo(A, B):
233233
let parse_ast = parse_expression(&source, "<test>").unwrap();
234234
insta::assert_debug_snapshot!(parse_ast);
235235
}
236+
237+
#[test]
238+
fn test_slice() {
239+
let source = String::from("x[1:2:3]");
240+
let parse_ast = parse_expression(&source, "<test>").unwrap();
241+
insta::assert_debug_snapshot!(parse_ast);
242+
}
236243
}

compiler/parser/src/snapshots/rustpython_parser__parser__tests__slice.snap

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

0 commit comments

Comments
 (0)