Skip to content

Commit aee2de9

Browse files
committed
Fix up doubled range in arguments
1 parent 7ea42f6 commit aee2de9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/prism.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14204,10 +14204,20 @@ parse_arguments(pm_parser_t *parser, pm_arguments_t *arguments, bool accepts_for
1420414204
parser_lex(parser);
1420514205

1420614206
if (token_begins_expression_p(parser->current.type)) {
14207-
// If the token begins an expression then this ... was not actually
14208-
// argument forwarding but was instead a range.
14207+
// If the token begins an expression then this ... was
14208+
// not actually argument forwarding but was instead a
14209+
// range.
1420914210
pm_token_t operator = parser->previous;
1421014211
pm_node_t *right = parse_expression(parser, PM_BINDING_POWER_RANGE, false, false, PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR, (uint16_t) (depth + 1));
14212+
14213+
// If we parse a range, we need to validate that we
14214+
// didn't accidentally violate the nonassoc rules of the
14215+
// ... operator.
14216+
if (PM_NODE_TYPE_P(right, PM_RANGE_NODE)) {
14217+
pm_range_node_t *range = (pm_range_node_t *) right;
14218+
pm_parser_err(parser, range->operator_loc.start, range->operator_loc.end, PM_ERR_UNEXPECTED_RANGE_OPERATOR);
14219+
}
14220+
1421114221
argument = (pm_node_t *) pm_range_node_create(parser, NULL, &operator, right);
1421214222
} else {
1421314223
pm_parser_scope_forwarding_all_check(parser, &parser->previous);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
p(...1...)
2+
^~~ unexpected range operator; .. and ... are non-associative and cannot be chained
3+

0 commit comments

Comments
 (0)