From 6e2b139d6ac1bcbae26c06a4e3022e8b2be8307e Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Tue, 6 May 2025 09:30:03 -0400 Subject: [ruby/prism] Ensure context terminators terminate expressions https://github.com/ruby/prism/commit/915f6b3ae9 --- prism/prism.c | 6 ++++++ test/prism/fixtures/case_in_hash_key.txt | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 test/prism/fixtures/case_in_hash_key.txt diff --git a/prism/prism.c b/prism/prism.c index 9d2598e746..4d2c372d5d 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -22176,6 +22176,12 @@ 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 diff --git a/test/prism/fixtures/case_in_hash_key.txt b/test/prism/fixtures/case_in_hash_key.txt new file mode 100644 index 0000000000..75ac8a846f --- /dev/null +++ b/test/prism/fixtures/case_in_hash_key.txt @@ -0,0 +1,6 @@ +case 1 +in 2 + A.print message: +in 3 + A.print message: +end -- cgit v1.2.3