diff options
author | Stan Lo <[email protected]> | 2025-07-17 12:29:40 +0100 |
---|---|---|
committer | git <[email protected]> | 2025-07-17 16:06:34 +0000 |
commit | 13de248f391ce41a83b86c61fc05202886296b57 (patch) | |
tree | b6eb50821cd3f6c4e0c1f8df4f407c702efea667 | |
parent | a46309d19a321b110bbb5a7887b8bf94eb1ae63f (diff) |
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.
https://github.com/ruby/prism/commit/70413ed4dd
-rw-r--r-- | prism/prism.c | 2 | ||||
-rw-r--r-- | test/prism/fixtures/endless_methods.txt | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/prism/prism.c b/prism/prism.c index 85647020d8..0db0ee4672 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -19520,7 +19520,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b pm_do_loop_stack_push(parser, false); statements = (pm_node_t *) pm_statements_node_create(parser); - 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)); + pm_node_t *statement = parse_expression(parser, PM_BINDING_POWER_DEFINED + 1, true, false, PM_ERR_DEF_ENDLESS, (uint16_t) (depth + 1)); if (accept1(parser, PM_TOKEN_KEYWORD_RESCUE_MODIFIER)) { context_push(parser, PM_CONTEXT_RESCUE_MODIFIER); diff --git a/test/prism/fixtures/endless_methods.txt b/test/prism/fixtures/endless_methods.txt index 8c2f2a30cc..7eb3bf4318 100644 --- a/test/prism/fixtures/endless_methods.txt +++ b/test/prism/fixtures/endless_methods.txt @@ -3,3 +3,5 @@ def foo = 1 def bar = A "" def method = 1 + 2 + 3 + +x = def f = p 1 |