[ruby/prism] Reject pattern match with unexpected double splat inside array

`a => [-2**b]` should be SyntaxError

Fixes: https://github.com/ruby/prism/issues/3381

https://github.com/ruby/prism/commit/ae8e83b389
This commit is contained in:
ydah 2025-01-08 23:58:59 +09:00 committed by git
parent e0d600ec19
commit 500a87756f
2 changed files with 16 additions and 1 deletions

View File

@ -20527,12 +20527,13 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
return (pm_node_t *) node;
}
case PM_TOKEN_UMINUS_NUM: {
pm_token_t prev = parser->previous;
parser_lex(parser);
pm_token_t operator = parser->previous;
pm_node_t *node = parse_expression(parser, pm_binding_powers[parser->previous.type].right, false, false, PM_ERR_UNARY_RECEIVER, (uint16_t) (depth + 1));
if (accept1(parser, PM_TOKEN_STAR_STAR)) {
if ((prev.type != PM_TOKEN_BRACKET_LEFT_ARRAY) && (accept1(parser, PM_TOKEN_STAR_STAR))) {
pm_token_t exponent_operator = parser->previous;
pm_node_t *exponent = parse_expression(parser, pm_binding_powers[exponent_operator.type].right, false, false, PM_ERR_EXPECT_ARGUMENT, (uint16_t) (depth + 1));
node = (pm_node_t *) pm_call_node_binary_create(parser, node, &exponent_operator, exponent, 0);

View File

@ -0,0 +1,14 @@
a => [-2*b]
^ expected a `]` to close the pattern expression
^ unexpected '*', expecting end-of-input
^ unexpected '*', ignoring it
^ unexpected ']', expecting end-of-input
^ unexpected ']', ignoring it
a => [-2**b]
^ expected a `]` to close the pattern expression
^~ unexpected '**', expecting end-of-input
^~ unexpected '**', ignoring it
^ unexpected ']', expecting end-of-input
^ unexpected ']', ignoring it