Skip to content

Commit 9a65f00

Browse files
committed
Fix nested multi assignment locations
1 parent 1db2de9 commit 9a65f00

File tree

10 files changed

+57
-45
lines changed

10 files changed

+57
-45
lines changed

src/yarp.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,7 +3164,10 @@ yp_multi_write_node_create(yp_parser_t *parser, const yp_token_t *operator, yp_n
31643164
*node = (yp_multi_write_node_t) {
31653165
{
31663166
.type = YP_NODE_MULTI_WRITE_NODE,
3167-
.location = { .start = NULL, .end = NULL },
3167+
.location = {
3168+
.start = lparen_loc->start,
3169+
.end = value == NULL ? rparen_loc->end : value->location.end
3170+
},
31683171
},
31693172
.operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator),
31703173
.value = value,
@@ -8202,6 +8205,8 @@ parse_targets(yp_parser_t *parser, yp_node_t *first_target, yp_binding_power_t b
82028205

82038206
if (YP_NODE_TYPE_P(child_target, YP_NODE_MULTI_WRITE_NODE)) {
82048207
target = (yp_multi_write_node_t *) child_target;
8208+
target->base.location.start = lparen.start;
8209+
target->base.location.end = rparen.end;
82058210
target->lparen_loc = (yp_location_t) { .start = lparen.start, .end = lparen.end };
82068211
target->rparen_loc = (yp_location_t) { .start = rparen.start, .end = rparen.end };
82078212
} else {
@@ -8218,6 +8223,7 @@ parse_targets(yp_parser_t *parser, yp_node_t *first_target, yp_binding_power_t b
82188223
yp_multi_write_node_targets_append(target, child_target);
82198224
}
82208225

8226+
target->base.location.start = lparen.start;
82218227
target->base.location.end = rparen.end;
82228228
yp_multi_write_node_targets_append(result, (yp_node_t *) target);
82238229
}
@@ -10690,10 +10696,8 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
1069010696
}
1069110697
case YP_TOKEN_PARENTHESIS_LEFT:
1069210698
case YP_TOKEN_PARENTHESIS_LEFT_PARENTHESES: {
10693-
yp_token_type_t current_token_type = parser->current.type;
10699+
yp_token_t opening = parser->current;
1069410700
parser_lex(parser);
10695-
10696-
yp_token_t opening = parser->previous;
1069710701
while (accept_any(parser, 2, YP_TOKEN_SEMICOLON, YP_TOKEN_NEWLINE));
1069810702

1069910703
// If this is the end of the file or we match a right parenthesis, then
@@ -10712,7 +10716,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
1071210716
// If we hit a right parenthesis, then we're done parsing the parentheses
1071310717
// node, and we can check which kind of node we should return.
1071410718
if (match_type_p(parser, YP_TOKEN_PARENTHESIS_RIGHT)) {
10715-
if (current_token_type == YP_TOKEN_PARENTHESIS_LEFT_PARENTHESES) {
10719+
if (opening.type == YP_TOKEN_PARENTHESIS_LEFT_PARENTHESES) {
1071610720
lex_state_set(parser, YP_LEX_STATE_ENDARG);
1071710721
}
1071810722
parser_lex(parser);
@@ -10730,6 +10734,8 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
1073010734

1073110735
if (multi_statement->lparen_loc.start == NULL) {
1073210736
multi_write = (yp_multi_write_node_t *) statement;
10737+
multi_write->base.location.start = lparen_loc.start;
10738+
multi_write->base.location.end = rparen_loc.end;
1073310739
multi_write->lparen_loc = lparen_loc;
1073410740
multi_write->rparen_loc = rparen_loc;
1073510741
} else {
@@ -10781,6 +10787,8 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
1078110787
yp_accepts_block_stack_pop(parser);
1078210788
expect(parser, YP_TOKEN_PARENTHESIS_RIGHT, "Expected a closing parenthesis.");
1078310789

10790+
10791+
1078410792
return (yp_node_t *) yp_parentheses_node_create(parser, &opening, (yp_node_t *) statements, &parser->previous);
1078510793
}
1078610794
case YP_TOKEN_BRACE_LEFT: {

test/snapshots/lambda.txt

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/snapshots/seattlerb/masgn_double_paren.txt

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/snapshots/seattlerb/masgn_paren.txt

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/snapshots/unparser/corpus/literal/assignment.txt

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/snapshots/unparser/corpus/literal/defined.txt

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/snapshots/unparser/corpus/literal/send.txt

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/snapshots/variables.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/snapshots/whitequark/masgn.txt

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/snapshots/whitequark/masgn_nested.txt

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)