Skip to content

Commit ee181d1

Browse files
kddnewtonmatzbot
authored andcommitted
[ruby/prism] Fix up it indirect writes
Fixes [Bug #21137] ruby/prism@ca493e6797
1 parent 0cab608 commit ee181d1

File tree

3 files changed

+477
-2
lines changed

3 files changed

+477
-2
lines changed

prism/prism.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5662,7 +5662,7 @@ pm_lambda_node_create(
56625662
*/
56635663
static pm_local_variable_and_write_node_t *
56645664
pm_local_variable_and_write_node_create(pm_parser_t *parser, pm_node_t *target, const pm_token_t *operator, pm_node_t *value, pm_constant_id_t name, uint32_t depth) {
5665-
assert(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_READ_NODE) || PM_NODE_TYPE_P(target, PM_CALL_NODE));
5665+
assert(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_READ_NODE) || PM_NODE_TYPE_P(target, PM_IT_LOCAL_VARIABLE_READ_NODE) || PM_NODE_TYPE_P(target, PM_CALL_NODE));
56665666
assert(operator->type == PM_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
56675667
pm_local_variable_and_write_node_t *node = PM_NODE_ALLOC(parser, pm_local_variable_and_write_node_t);
56685668

@@ -5717,7 +5717,7 @@ pm_local_variable_operator_write_node_create(pm_parser_t *parser, pm_node_t *tar
57175717
*/
57185718
static pm_local_variable_or_write_node_t *
57195719
pm_local_variable_or_write_node_create(pm_parser_t *parser, pm_node_t *target, const pm_token_t *operator, pm_node_t *value, pm_constant_id_t name, uint32_t depth) {
5720-
assert(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_READ_NODE) || PM_NODE_TYPE_P(target, PM_CALL_NODE));
5720+
assert(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_READ_NODE) || PM_NODE_TYPE_P(target, PM_IT_LOCAL_VARIABLE_READ_NODE) || PM_NODE_TYPE_P(target, PM_CALL_NODE));
57215721
assert(operator->type == PM_TOKEN_PIPE_PIPE_EQUAL);
57225722
pm_local_variable_or_write_node_t *node = PM_NODE_ALLOC(parser, pm_local_variable_or_write_node_t);
57235723

@@ -21218,6 +21218,17 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
2121821218
pm_node_destroy(parser, node);
2121921219
return result;
2122021220
}
21221+
case PM_IT_LOCAL_VARIABLE_READ_NODE: {
21222+
pm_constant_id_t name = pm_parser_local_add_constant(parser, "it", 2);
21223+
parser_lex(parser);
21224+
21225+
pm_node_t *value = parse_assignment_value(parser, previous_binding_power, binding_power, accepts_command_call, PM_ERR_EXPECT_EXPRESSION_AFTER_AMPAMPEQ, (uint16_t) (depth + 1));
21226+
pm_node_t *result = (pm_node_t *) pm_local_variable_and_write_node_create(parser, node, &token, value, name, 0);
21227+
21228+
parse_target_implicit_parameter(parser, node);
21229+
pm_node_destroy(parser, node);
21230+
return result;
21231+
}
2122121232
case PM_LOCAL_VARIABLE_READ_NODE: {
2122221233
if (pm_token_is_numbered_parameter(node->location.start, node->location.end)) {
2122321234
PM_PARSER_ERR_FORMAT(parser, node->location.start, node->location.end, PM_ERR_PARAMETER_NUMBERED_RESERVED, node->location.start);
@@ -21341,6 +21352,17 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
2134121352
pm_node_destroy(parser, node);
2134221353
return result;
2134321354
}
21355+
case PM_IT_LOCAL_VARIABLE_READ_NODE: {
21356+
pm_constant_id_t name = pm_parser_local_add_constant(parser, "it", 2);
21357+
parser_lex(parser);
21358+
21359+
pm_node_t *value = parse_assignment_value(parser, previous_binding_power, binding_power, accepts_command_call, PM_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ, (uint16_t) (depth + 1));
21360+
pm_node_t *result = (pm_node_t *) pm_local_variable_or_write_node_create(parser, node, &token, value, name, 0);
21361+
21362+
parse_target_implicit_parameter(parser, node);
21363+
pm_node_destroy(parser, node);
21364+
return result;
21365+
}
2134421366
case PM_LOCAL_VARIABLE_READ_NODE: {
2134521367
if (pm_token_is_numbered_parameter(node->location.start, node->location.end)) {
2134621368
PM_PARSER_ERR_FORMAT(parser, node->location.start, node->location.end, PM_ERR_PARAMETER_NUMBERED_RESERVED, node->location.start);
@@ -21474,6 +21496,17 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
2147421496
pm_node_destroy(parser, node);
2147521497
return result;
2147621498
}
21499+
case PM_IT_LOCAL_VARIABLE_READ_NODE: {
21500+
pm_constant_id_t name = pm_parser_local_add_constant(parser, "it", 2);
21501+
parser_lex(parser);
21502+
21503+
pm_node_t *value = parse_assignment_value(parser, previous_binding_power, binding_power, accepts_command_call, PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR, (uint16_t) (depth + 1));
21504+
pm_node_t *result = (pm_node_t *) pm_local_variable_operator_write_node_create(parser, node, &token, value, name, 0);
21505+
21506+
parse_target_implicit_parameter(parser, node);
21507+
pm_node_destroy(parser, node);
21508+
return result;
21509+
}
2147721510
case PM_LOCAL_VARIABLE_READ_NODE: {
2147821511
if (pm_token_is_numbered_parameter(node->location.start, node->location.end)) {
2147921512
PM_PARSER_ERR_FORMAT(parser, node->location.start, node->location.end, PM_ERR_PARAMETER_NUMBERED_RESERVED, node->location.start);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
tap { it += 1 }
2+
3+
tap { it ||= 1 }
4+
5+
tap { it &&= 1 }
6+
7+
tap { it; it += 1 }
8+
9+
tap { it; it ||= 1 }
10+
11+
tap { it; it &&= 1 }
12+
13+
tap { it += 1; it }
14+
15+
tap { it ||= 1; it }
16+
17+
tap { it &&= 1; it }
18+
19+
tap { it; it += 1; it }
20+
21+
tap { it; it ||= 1; it }
22+
23+
tap { it; it &&= 1; it }

0 commit comments

Comments
 (0)