Skip to content

Commit 3c22e6f

Browse files
committed
Use pm_arguments_end for function call
Previously, the location of CallNode was incorrect when it accepts a block parameter: ``` $ ruby -rprism -e 'pp Prism.parse("foo(&blk)").value.statements.body[0]'] @ CallNode (location: (1,0)-(1,8)) # <=== It should be (1,0)-(1,9) ├── flags: ∅ ├── receiver: ∅ ├── call_operator_loc: ∅ ├── name: :foo ├── message_loc: (1,0)-(1,3) = "foo" ├── opening_loc: (1,3)-(1,4) = "(" ├── arguments: ∅ ├── closing_loc: (1,8)-(1,9) = ")" *snip* $ ruby -rprism -e 'pp Prism.parse("foo(&blk)").value.statements.body[0].slice' "foo(&blk" ``` Note that the slice lacks the closing parenthesis.
1 parent 65958ed commit 3c22e6f

File tree

10 files changed

+31
-37
lines changed

10 files changed

+31
-37
lines changed

snapshots/method_calls.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
│ ├── arguments: ∅
279279
│ ├── closing_loc: ∅
280280
│ └── block: ∅
281-
├── @ CallNode (location: (25,0)-(25,8))
281+
├── @ CallNode (location: (25,0)-(25,9))
282282
│ ├── flags: newline, ignore_visibility
283283
│ ├── receiver: ∅
284284
│ ├── call_operator_loc: ∅
@@ -781,7 +781,7 @@
781781
│ │ └── block: ∅
782782
│ ├── closing_loc: (58,9)-(58,10) = ")"
783783
│ └── block: ∅
784-
├── @ CallNode (location: (60,0)-(60,39))
784+
├── @ CallNode (location: (60,0)-(60,40))
785785
│ ├── flags: newline, ignore_visibility
786786
│ ├── receiver: ∅
787787
│ ├── call_operator_loc: ∅
@@ -1156,7 +1156,7 @@
11561156
│ │ └── operator_loc: ∅
11571157
│ ├── closing_loc: (70,40)-(70,41) = ")"
11581158
│ └── block: ∅
1159-
├── @ CallNode (location: (72,0)-(72,35))
1159+
├── @ CallNode (location: (72,0)-(72,36))
11601160
│ ├── flags: newline, ignore_visibility
11611161
│ ├── receiver: ∅
11621162
│ ├── call_operator_loc: ∅

snapshots/seattlerb/call_block_arg_named.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
@ ProgramNode (location: (1,0)-(1,6))
1+
@ ProgramNode (location: (1,0)-(1,7))
22
├── flags: ∅
33
├── locals: []
44
└── statements:
5-
@ StatementsNode (location: (1,0)-(1,6))
5+
@ StatementsNode (location: (1,0)-(1,7))
66
├── flags: ∅
77
└── body: (length: 1)
8-
└── @ CallNode (location: (1,0)-(1,6))
8+
└── @ CallNode (location: (1,0)-(1,7))
99
├── flags: newline, ignore_visibility
1010
├── receiver: ∅
1111
├── call_operator_loc: ∅

snapshots/unparser/corpus/literal/send.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@
813813
│ │ └── unescaped: "bar"
814814
│ ├── closing_loc: ∅
815815
│ └── block: ∅
816-
├── @ CallNode (location: (50,0)-(50,17))
816+
├── @ CallNode (location: (50,0)-(50,18))
817817
│ ├── flags: newline, ignore_visibility
818818
│ ├── receiver: ∅
819819
│ ├── call_operator_loc: ∅
@@ -860,7 +860,7 @@
860860
│ │ ├── opening_loc: (50,5)-(50,6) = "("
861861
│ │ └── closing_loc: (50,16)-(50,17) = ")"
862862
│ └── operator_loc: (50,4)-(50,5) = "&"
863-
├── @ CallNode (location: (51,0)-(51,10))
863+
├── @ CallNode (location: (51,0)-(51,11))
864864
│ ├── flags: newline, ignore_visibility
865865
│ ├── receiver: ∅
866866
│ ├── call_operator_loc: ∅
@@ -884,7 +884,7 @@
884884
│ │ ├── closing_loc: ∅
885885
│ │ └── block: ∅
886886
│ └── operator_loc: (51,4)-(51,5) = "&"
887-
├── @ CallNode (location: (52,0)-(52,17))
887+
├── @ CallNode (location: (52,0)-(52,18))
888888
│ ├── flags: newline, ignore_visibility
889889
│ ├── receiver: ∅
890890
│ ├── call_operator_loc: ∅

snapshots/unparser/corpus/literal/since/31.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
│ │ ├── name_loc: ∅
2727
│ │ └── operator_loc: (1,8)-(1,9) = "&"
2828
│ ├── body:
29-
│ │ @ StatementsNode (location: (2,2)-(2,7))
29+
│ │ @ StatementsNode (location: (2,2)-(2,8))
3030
│ │ ├── flags: ∅
3131
│ │ └── body: (length: 1)
32-
│ │ └── @ CallNode (location: (2,2)-(2,7))
32+
│ │ └── @ CallNode (location: (2,2)-(2,8))
3333
│ │ ├── flags: newline, ignore_visibility
3434
│ │ ├── receiver: ∅
3535
│ │ ├── call_operator_loc: ∅
@@ -74,10 +74,10 @@
7474
│ ├── name_loc: ∅
7575
│ └── operator_loc: (5,11)-(5,12) = "&"
7676
├── body:
77-
│ @ StatementsNode (location: (6,2)-(6,7))
77+
│ @ StatementsNode (location: (6,2)-(6,8))
7878
│ ├── flags: ∅
7979
│ └── body: (length: 1)
80-
│ └── @ CallNode (location: (6,2)-(6,7))
80+
│ └── @ CallNode (location: (6,2)-(6,8))
8181
│ ├── flags: newline, ignore_visibility
8282
│ ├── receiver: ∅
8383
│ ├── call_operator_loc: ∅

snapshots/whitequark/anonymous_blockarg.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
│ ├── name_loc: ∅
2727
│ └── operator_loc: (1,8)-(1,9) = "&"
2828
├── body:
29-
│ @ StatementsNode (location: (1,12)-(1,17))
29+
│ @ StatementsNode (location: (1,12)-(1,18))
3030
│ ├── flags: ∅
3131
│ └── body: (length: 1)
32-
│ └── @ CallNode (location: (1,12)-(1,17))
32+
│ └── @ CallNode (location: (1,12)-(1,18))
3333
│ ├── flags: newline, ignore_visibility
3434
│ ├── receiver: ∅
3535
│ ├── call_operator_loc: ∅

snapshots/whitequark/args_args_assocs.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@ ProgramNode (location: (1,0)-(3,24))
1+
@ ProgramNode (location: (1,0)-(3,25))
22
├── flags: ∅
33
├── locals: []
44
└── statements:
5-
@ StatementsNode (location: (1,0)-(3,24))
5+
@ StatementsNode (location: (1,0)-(3,25))
66
├── flags: ∅
77
└── body: (length: 2)
88
├── @ CallNode (location: (1,0)-(1,19))
@@ -45,7 +45,7 @@
4545
│ │ └── operator_loc: (1,14)-(1,16) = "=>"
4646
│ ├── closing_loc: (1,18)-(1,19) = ")"
4747
│ └── block: ∅
48-
└── @ CallNode (location: (3,0)-(3,24))
48+
└── @ CallNode (location: (3,0)-(3,25))
4949
├── flags: newline, ignore_visibility
5050
├── receiver: ∅
5151
├── call_operator_loc: ∅

snapshots/whitequark/args_args_star.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@ ProgramNode (location: (1,0)-(3,19))
1+
@ ProgramNode (location: (1,0)-(3,20))
22
├── flags: ∅
33
├── locals: []
44
└── statements:
5-
@ StatementsNode (location: (1,0)-(3,19))
5+
@ StatementsNode (location: (1,0)-(3,20))
66
├── flags: ∅
77
└── body: (length: 2)
88
├── @ CallNode (location: (1,0)-(1,14))
@@ -42,7 +42,7 @@
4242
│ │ └── block: ∅
4343
│ ├── closing_loc: (1,13)-(1,14) = ")"
4444
│ └── block: ∅
45-
└── @ CallNode (location: (3,0)-(3,19))
45+
└── @ CallNode (location: (3,0)-(3,20))
4646
├── flags: newline, ignore_visibility
4747
├── receiver: ∅
4848
├── call_operator_loc: ∅

snapshots/whitequark/args_block_pass.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
@ ProgramNode (location: (1,0)-(1,8))
1+
@ ProgramNode (location: (1,0)-(1,9))
22
├── flags: ∅
33
├── locals: []
44
└── statements:
5-
@ StatementsNode (location: (1,0)-(1,8))
5+
@ StatementsNode (location: (1,0)-(1,9))
66
├── flags: ∅
77
└── body: (length: 1)
8-
└── @ CallNode (location: (1,0)-(1,8))
8+
└── @ CallNode (location: (1,0)-(1,9))
99
├── flags: newline, ignore_visibility
1010
├── receiver: ∅
1111
├── call_operator_loc: ∅

snapshots/whitequark/args_star.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@ ProgramNode (location: (1,0)-(3,14))
1+
@ ProgramNode (location: (1,0)-(3,15))
22
├── flags: ∅
33
├── locals: []
44
└── statements:
5-
@ StatementsNode (location: (1,0)-(3,14))
5+
@ StatementsNode (location: (1,0)-(3,15))
66
├── flags: ∅
77
└── body: (length: 2)
88
├── @ CallNode (location: (1,0)-(1,9))
@@ -32,7 +32,7 @@
3232
│ │ └── block: ∅
3333
│ ├── closing_loc: (1,8)-(1,9) = ")"
3434
│ └── block: ∅
35-
└── @ CallNode (location: (3,0)-(3,14))
35+
└── @ CallNode (location: (3,0)-(3,15))
3636
├── flags: newline, ignore_visibility
3737
├── receiver: ∅
3838
├── call_operator_loc: ∅

src/prism.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18570,17 +18570,11 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1857018570
call->closing_loc = arguments.closing_loc;
1857118571
call->block = arguments.block;
1857218572

18573-
if (arguments.block != NULL) {
18574-
call->base.location.end = arguments.block->location.end;
18575-
} else if (arguments.closing_loc.start == NULL) {
18576-
if (arguments.arguments != NULL) {
18577-
call->base.location.end = arguments.arguments->base.location.end;
18578-
} else {
18579-
call->base.location.end = call->message_loc.end;
18580-
}
18581-
} else {
18582-
call->base.location.end = arguments.closing_loc.end;
18573+
const uint8_t *end = pm_arguments_end(&arguments);
18574+
if (!end) {
18575+
end = call->message_loc.end;
1858318576
}
18577+
call->base.location.end = end;
1858418578
}
1858518579
} else {
1858618580
// Otherwise, we know the identifier is in the local table. This

0 commit comments

Comments
 (0)