Skip to content

Commit 3c07567

Browse files
kddnewtonmatzbot
authored andcommitted
[ruby/prism] Better error message on statement inside argument list
ruby/prism@3b1a99526a
1 parent 10d0abb commit 3c07567

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

prism/prism.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14335,9 +14335,14 @@ parse_arguments_list(pm_parser_t *parser, pm_arguments_t *arguments, bool accept
1433514335
} else {
1433614336
pm_accepts_block_stack_push(parser, true);
1433714337
parse_arguments(parser, arguments, true, PM_TOKEN_PARENTHESIS_RIGHT);
14338-
expect1(parser, PM_TOKEN_PARENTHESIS_RIGHT, PM_ERR_ARGUMENT_TERM_PAREN);
14339-
pm_accepts_block_stack_pop(parser);
1434014338

14339+
if (!accept1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) {
14340+
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_ARGUMENT_TERM_PAREN, pm_token_type_human(parser->current.type));
14341+
parser->previous.start = parser->previous.end;
14342+
parser->previous.type = PM_TOKEN_MISSING;
14343+
}
14344+
14345+
pm_accepts_block_stack_pop(parser);
1434114346
arguments->closing_loc = PM_LOCATION_TOKEN_VALUE(&parser->previous);
1434214347
}
1434314348
} 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)) {

prism/templates/src/diagnostic.c.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
105105
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR] = { "unexpected `**`; no anonymous keyword rest parameter", PM_ERROR_LEVEL_SYNTAX },
106106
[PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT] = { "unexpected `*` splat argument after a `**` keyword splat argument", PM_ERROR_LEVEL_SYNTAX },
107107
[PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT] = { "unexpected `*` splat argument after a `*` splat argument", PM_ERROR_LEVEL_SYNTAX },
108-
[PM_ERR_ARGUMENT_TERM_PAREN] = { "expected a `)` to close the arguments", PM_ERROR_LEVEL_SYNTAX },
108+
[PM_ERR_ARGUMENT_TERM_PAREN] = { "unexpected %s; expected a `)` to close the arguments", PM_ERROR_LEVEL_SYNTAX },
109109
[PM_ERR_ARGUMENT_UNEXPECTED_BLOCK] = { "unexpected `{` after a method call without parenthesis", PM_ERROR_LEVEL_SYNTAX },
110110
[PM_ERR_ARRAY_ELEMENT] = { "expected an element for the array", PM_ERROR_LEVEL_SYNTAX },
111111
[PM_ERR_ARRAY_EXPRESSION] = { "expected an expression for the array element", PM_ERROR_LEVEL_SYNTAX },

prism/templates/src/token_type.c.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pm_token_type_human(pm_token_type_t token_type) {
208208
case PM_TOKEN_KEYWORD_RESCUE:
209209
return "'rescue'";
210210
case PM_TOKEN_KEYWORD_RESCUE_MODIFIER:
211-
return "'rescue'";
211+
return "'rescue' modifier";
212212
case PM_TOKEN_KEYWORD_RETRY:
213213
return "'retry'";
214214
case PM_TOKEN_KEYWORD_RETURN:

test/prism/errors_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def test_arguments_after_block
411411

412412
def test_arguments_binding_power_for_and
413413
assert_error_messages "foo(*bar and baz)", [
414-
"expected a `)` to close the arguments",
414+
"unexpected 'and'; expected a `)` to close the arguments",
415415
"unexpected ')', expecting end-of-input",
416416
"unexpected ')', ignoring it"
417417
]

0 commit comments

Comments
 (0)