Skip to content

Commit e5d6b40

Browse files
haldunmatzbot
authored andcommitted
[ruby/prism] Do not allow trailing commas in calls without parenthesis
ruby/prism@f1d56da58f
1 parent db4303f commit e5d6b40

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

prism/prism.c

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

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

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)