Skip to content

Commit e39fd45

Browse files
mamematzbot
authored andcommitted
[ruby/prism] 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. ruby/prism@3c22e6fc39
1 parent 17039c5 commit e39fd45

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

prism/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)