Skip to content

Commit f1d56da

Browse files
committed
Do not allow trailing commas in calls without parenthesis
1 parent 5da0672 commit f1d56da

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/prism.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11921,6 +11921,13 @@ parse_arguments_list(pm_parser_t *parser, pm_arguments_t *arguments, bool accept
1192111921
// argument to this method call.
1192211922
parse_arguments(parser, arguments, true, PM_TOKEN_EOF);
1192311923

11924+
// If we have done with the arguments and still not consumed the comma,
11925+
// then we have a trailing comma where we need to check whether it is
11926+
// allowed or not.
11927+
if (parser->previous.type == PM_TOKEN_COMMA && !match1(parser, PM_TOKEN_SEMICOLON)) {
11928+
pm_parser_err_previous(parser, PM_ERR_EXPECT_ARGUMENT);
11929+
}
11930+
1192411931
pm_accepts_block_stack_pop(parser);
1192511932
}
1192611933

test/prism/errors_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,12 @@ def test_void_value_expression_in_binary_call
16761676
], compare_ripper: false # Ripper does not check 'void value expression'.
16771677
end
16781678

1679+
def test_trailing_comma_in_calls
1680+
assert_errors expression("foo 1,"), "foo 1,", [
1681+
["Expected an argument", 5..6]
1682+
]
1683+
end
1684+
16791685
private
16801686

16811687
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")

0 commit comments

Comments
 (0)