Skip to content

Commit b5a768b

Browse files
kddnewtonk0kubun
authored andcommitted
[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] ruby/prism@20374ced51
1 parent e7d2828 commit b5a768b

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

prism/prism.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21678,12 +21678,6 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
2167821678
) {
2167921679
node = parse_expression_infix(parser, node, binding_power, current_binding_powers.right, accepts_command_call, (uint16_t) (depth + 1));
2168021680

21681-
if (context_terminator(parser->current_context->context, &parser->current)) {
21682-
// If this token terminates the current context, then we need to
21683-
// stop parsing the expression, as it has become a statement.
21684-
return node;
21685-
}
21686-
2168721681
switch (PM_NODE_TYPE(node)) {
2168821682
case PM_MULTI_WRITE_NODE:
2168921683
// 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
2179621790
break;
2179721791
}
2179821792
}
21793+
21794+
if (context_terminator(parser->current_context->context, &parser->current)) {
21795+
pm_binding_powers_t next_binding_powers = pm_binding_powers[parser->current.type];
21796+
if (
21797+
!next_binding_powers.binary ||
21798+
binding_power > next_binding_powers.left ||
21799+
(PM_NODE_TYPE_P(node, PM_CALL_NODE) && pm_call_node_command_p((pm_call_node_t *) node))
21800+
) {
21801+
return node;
21802+
}
21803+
}
2179921804
}
2180021805

2180121806
return node;

test/prism/fixtures/case_in_in.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
case args
2+
in [event]
3+
context.event in ^event
4+
end

0 commit comments

Comments
 (0)