[ruby/prism] Fix in handling

in is a unique keyword because it can be the start of a clause or
an infix keyword. We need to be explicitly sure that even though in
_could_ close an expression context (the body of another in clause)
that we are not also parsing an inline in. The exception is the
case of a command call, which can never be the LHS of an expression,
and so we must immediately exit.

[Bug #21925]
[Bug #21674]

https://github.com/ruby/prism/commit/20374ced51
This commit is contained in:
Kevin Newton 2026-03-02 11:49:29 -05:00 committed by Takashi Kokubun
parent e7d2828fb6
commit b5a768b666
2 changed files with 15 additions and 6 deletions

View File

@ -21678,12 +21678,6 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
) {
node = parse_expression_infix(parser, node, binding_power, current_binding_powers.right, accepts_command_call, (uint16_t) (depth + 1));
if (context_terminator(parser->current_context->context, &parser->current)) {
// If this token terminates the current context, then we need to
// stop parsing the expression, as it has become a statement.
return node;
}
switch (PM_NODE_TYPE(node)) {
case PM_MULTI_WRITE_NODE:
// Multi-write nodes are statements, and cannot be followed by
@ -21796,6 +21790,17 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
break;
}
}
if (context_terminator(parser->current_context->context, &parser->current)) {
pm_binding_powers_t next_binding_powers = pm_binding_powers[parser->current.type];
if (
!next_binding_powers.binary ||
binding_power > next_binding_powers.left ||
(PM_NODE_TYPE_P(node, PM_CALL_NODE) && pm_call_node_command_p((pm_call_node_t *) node))
) {
return node;
}
}
}
return node;

View File

@ -0,0 +1,4 @@
case args
in [event]
context.event in ^event
end