diff options
author | Haldun Bayhantopcu <haldun@github.com> | 2023-09-27 21:31:49 +0200 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-09-28 13:24:57 +0000 |
commit | 0084bac47a49d787a86c4cfd4d238c24736eb659 (patch) | |
tree | 85cfb20644486e4fabeaac08832ec392ca8affca /prism | |
parent | bf335bcb11501d56915240d06cb556235084b0f2 (diff) | |
download | ruby-0084bac47a49d787a86c4cfd4d238c24736eb659.tar.gz |
[ruby/prism] Fix assertion failure for fwd params after rest
https://github.com/ruby/prism/commit/f86bff6dd7
Diffstat (limited to 'prism')
-rw-r--r-- | prism/diagnostic.c | 1 | ||||
-rw-r--r-- | prism/diagnostic.h | 1 | ||||
-rw-r--r-- | prism/prism.c | 8 |
3 files changed, 10 insertions, 0 deletions
diff --git a/prism/diagnostic.c b/prism/diagnostic.c index d54bbe87ec..b8b92f97e0 100644 --- a/prism/diagnostic.c +++ b/prism/diagnostic.c @@ -202,6 +202,7 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = { [PM_ERR_PARAMETER_ORDER] = "Unexpected parameter order", [PM_ERR_PARAMETER_SPLAT_MULTI] = "Unexpected multiple `*` splat parameters", [PM_ERR_PARAMETER_STAR] = "Unexpected parameter `*`", + [PM_ERR_PARAMETER_UNEXPECTED_FWD] = "Unexpected `...` in parameters", [PM_ERR_PARAMETER_WILD_LOOSE_COMMA] = "Unexpected `,` in parameters", [PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET] = "Expected a pattern expression after the `[` operator", [PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA] = "Expected a pattern expression after `,`", diff --git a/prism/diagnostic.h b/prism/diagnostic.h index c9b21d42b7..33bf381d61 100644 --- a/prism/diagnostic.h +++ b/prism/diagnostic.h @@ -168,6 +168,7 @@ typedef enum { PM_ERR_PARAMETER_ORDER, PM_ERR_PARAMETER_SPLAT_MULTI, PM_ERR_PARAMETER_STAR, + PM_ERR_PARAMETER_UNEXPECTED_FWD, PM_ERR_PARAMETER_WILD_LOOSE_COMMA, PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET, PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET, diff --git a/prism/prism.c b/prism/prism.c index 98cfa0ce88..f1438b8132 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -9292,6 +9292,14 @@ parse_parameters( pm_parser_local_add_token(parser, &parser->previous); pm_forwarding_parameter_node_t *param = pm_forwarding_parameter_node_create(parser, &parser->previous); + if (params->keyword_rest != NULL) { + // If we already have a keyword rest parameter, then we replace it with the + // forwarding parameter and move the keyword rest parameter to the posts list. + pm_node_t *keyword_rest = params->keyword_rest; + pm_parameters_node_posts_append(params, keyword_rest); + pm_diagnostic_list_append(&parser->error_list, parser->previous.start, parser->previous.end, PM_ERR_PARAMETER_UNEXPECTED_FWD); + params->keyword_rest = NULL; + } pm_parameters_node_keyword_rest_set(params, (pm_node_t *)param); } else { update_parameter_state(parser, &parser->current, &order); |