[ruby/prism] Better error message on statement inside argument list

https://github.com/ruby/prism/commit/3b1a99526a
This commit is contained in:
Kevin Newton 2024-04-12 14:11:30 -04:00 committed by git
parent 10d0abb437
commit 3c0756752c
4 changed files with 10 additions and 5 deletions

View File

@ -14335,9 +14335,14 @@ parse_arguments_list(pm_parser_t *parser, pm_arguments_t *arguments, bool accept
} else {
pm_accepts_block_stack_push(parser, true);
parse_arguments(parser, arguments, true, PM_TOKEN_PARENTHESIS_RIGHT);
expect1(parser, PM_TOKEN_PARENTHESIS_RIGHT, PM_ERR_ARGUMENT_TERM_PAREN);
pm_accepts_block_stack_pop(parser);
if (!accept1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) {
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_ARGUMENT_TERM_PAREN, pm_token_type_human(parser->current.type));
parser->previous.start = parser->previous.end;
parser->previous.type = PM_TOKEN_MISSING;
}
pm_accepts_block_stack_pop(parser);
arguments->closing_loc = PM_LOCATION_TOKEN_VALUE(&parser->previous);
}
} else if (accepts_command_call && (token_begins_expression_p(parser->current.type) || match3(parser, PM_TOKEN_USTAR, PM_TOKEN_USTAR_STAR, PM_TOKEN_UAMPERSAND)) && !match1(parser, PM_TOKEN_BRACE_LEFT)) {

View File

@ -105,7 +105,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR] = { "unexpected `**`; no anonymous keyword rest parameter", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT] = { "unexpected `*` splat argument after a `**` keyword splat argument", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT] = { "unexpected `*` splat argument after a `*` splat argument", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_ARGUMENT_TERM_PAREN] = { "expected a `)` to close the arguments", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_ARGUMENT_TERM_PAREN] = { "unexpected %s; expected a `)` to close the arguments", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_ARGUMENT_UNEXPECTED_BLOCK] = { "unexpected `{` after a method call without parenthesis", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_ARRAY_ELEMENT] = { "expected an element for the array", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_ARRAY_EXPRESSION] = { "expected an expression for the array element", PM_ERROR_LEVEL_SYNTAX },

View File

@ -208,7 +208,7 @@ pm_token_type_human(pm_token_type_t token_type) {
case PM_TOKEN_KEYWORD_RESCUE:
return "'rescue'";
case PM_TOKEN_KEYWORD_RESCUE_MODIFIER:
return "'rescue'";
return "'rescue' modifier";
case PM_TOKEN_KEYWORD_RETRY:
return "'retry'";
case PM_TOKEN_KEYWORD_RETURN:

View File

@ -411,7 +411,7 @@ module Prism
def test_arguments_binding_power_for_and
assert_error_messages "foo(*bar and baz)", [
"expected a `)` to close the arguments",
"unexpected 'and'; expected a `)` to close the arguments",
"unexpected ')', expecting end-of-input",
"unexpected ')', ignoring it"
]