Skip to content

Commit 13de248

Browse files
st0012matzbot
authored andcommitted
[ruby/prism] Allow command calls in endless method bodies regardless of context
Previously, endless method definitions like `x = def f = p 1` would fail to parse because command calls (method calls without parentheses) were only accepted when the surrounding binding power was less than `PM_BINDING_POWER_COMPOSITION` (8). In assignment contexts with binding power 18, this condition was false, causing parse errors. This fix ensures command calls are always accepted in endless method bodies by passing `true` for `accepts_command_call`, making the method body parse consistently regardless of where the method is defined. ruby/prism@70413ed4dd
1 parent a46309d commit 13de248

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

prism/prism.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19520,7 +19520,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1952019520
pm_do_loop_stack_push(parser, false);
1952119521
statements = (pm_node_t *) pm_statements_node_create(parser);
1952219522

19523-
pm_node_t *statement = parse_expression(parser, PM_BINDING_POWER_DEFINED + 1, binding_power < PM_BINDING_POWER_COMPOSITION, false, PM_ERR_DEF_ENDLESS, (uint16_t) (depth + 1));
19523+
pm_node_t *statement = parse_expression(parser, PM_BINDING_POWER_DEFINED + 1, true, false, PM_ERR_DEF_ENDLESS, (uint16_t) (depth + 1));
1952419524

1952519525
if (accept1(parser, PM_TOKEN_KEYWORD_RESCUE_MODIFIER)) {
1952619526
context_push(parser, PM_CONTEXT_RESCUE_MODIFIER);

test/prism/fixtures/endless_methods.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ def foo = 1
33
def bar = A ""
44

55
def method = 1 + 2 + 3
6+
7+
x = def f = p 1

0 commit comments

Comments
 (0)