diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-10-02 11:16:52 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-10-02 15:27:01 +0000 |
| commit | 2610bf01b26b437df6a3634ffb7629b83ea57e17 (patch) | |
| tree | 90f4248a477ba4cf8f00b665d61b121763a33b62 | |
| parent | 609fdde2c99ad6b59a05808b96886bb6b71f3b8d (diff) | |
[ruby/prism] Fix up doubled range in arguments
https://github.com/ruby/prism/commit/aee2de91a3
| -rw-r--r-- | prism/prism.c | 14 | ||||
| -rw-r--r-- | test/prism/errors/range_doubled.txt | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/prism/prism.c b/prism/prism.c index 7b4b7828fd..03479b17b0 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -14203,10 +14203,20 @@ parse_arguments(pm_parser_t *parser, pm_arguments_t *arguments, bool accepts_for parser_lex(parser); if (token_begins_expression_p(parser->current.type)) { - // If the token begins an expression then this ... was not actually - // argument forwarding but was instead a range. + // If the token begins an expression then this ... was + // not actually argument forwarding but was instead a + // range. pm_token_t operator = parser->previous; pm_node_t *right = parse_expression(parser, PM_BINDING_POWER_RANGE, false, false, PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR, (uint16_t) (depth + 1)); + + // If we parse a range, we need to validate that we + // didn't accidentally violate the nonassoc rules of the + // ... operator. + if (PM_NODE_TYPE_P(right, PM_RANGE_NODE)) { + pm_range_node_t *range = (pm_range_node_t *) right; + pm_parser_err(parser, range->operator_loc.start, range->operator_loc.end, PM_ERR_UNEXPECTED_RANGE_OPERATOR); + } + argument = (pm_node_t *) pm_range_node_create(parser, NULL, &operator, right); } else { pm_parser_scope_forwarding_all_check(parser, &parser->previous); diff --git a/test/prism/errors/range_doubled.txt b/test/prism/errors/range_doubled.txt new file mode 100644 index 0000000000..ef63d1bede --- /dev/null +++ b/test/prism/errors/range_doubled.txt @@ -0,0 +1,3 @@ +p(...1...) + ^~~ unexpected range operator; .. and ... are non-associative and cannot be chained + |
