[ruby/prism] Fix assertion failure for fwd params after rest
https://github.com/ruby/prism/commit/f86bff6dd7
This commit is contained in:
parent
bf335bcb11
commit
0084bac47a
@ -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 `,`",
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -1348,6 +1348,13 @@ module Prism
|
||||
]
|
||||
end
|
||||
|
||||
def test_forwarding_arg_after_keyword_rest
|
||||
source = "def f(**,...);end"
|
||||
assert_errors expression(source), source, [
|
||||
["Unexpected `...` in parameters", 9..12],
|
||||
]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")
|
||||
|
Loading…
x
Reference in New Issue
Block a user