Skip to content

Commit 908244b

Browse files
committed
add a diagnostic for *rest in order after optional state
1 parent 9171a95 commit 908244b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/yarp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8340,6 +8340,10 @@ update_parameter_state(yp_parser_t *parser, yp_token_t *token, yp_parameters_ord
83408340
return;
83418341
}
83428342

8343+
if (token->type == YP_TOKEN_USTAR && *current == YP_PARAMETERS_ORDER_AFTER_OPTIONAL) {
8344+
yp_diagnostic_list_append(&parser->error_list, token->start, token->end, "Unexpected parameter *");
8345+
}
8346+
83438347
if (*current == YP_PARAMETERS_ORDER_NOTHING_AFTER || state > *current) {
83448348
// We know what transition we failed on, so we can provide a better error here.
83458349
yp_diagnostic_list_append(&parser->error_list, token->start, token->end, "Unexpected parameter order");

test/errors_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,22 @@ def test_duplicated_parameter_names
10591059
assert_errors expected, "def foo(a,b,&a);end", [
10601060
["Duplicated parameter name.", 13..14]
10611061
]
1062+
1063+
expected = DefNode(
1064+
Location(),
1065+
nil,
1066+
ParametersNode([], [OptionalParameterNode(:a, Location(), Location(), IntegerNode())], [RequiredParameterNode(:b)], RestParameterNode(Location(), Location()), [], nil, nil),
1067+
nil,
1068+
[:a, :b, :c],
1069+
Location(),
1070+
nil,
1071+
Location(),
1072+
Location(),
1073+
nil,
1074+
Location()
1075+
)
1076+
1077+
assert_errors expected, "def foo(a = 1,b,*c);end", [["Unexpected parameter *", 16..17]]
10621078
end
10631079

10641080
private

0 commit comments

Comments
 (0)