[ruby/yarp] add a diagnostic for *rest in order after optional state
https://github.com/ruby/yarp/commit/908244ba12
This commit is contained in:
parent
bf723b21cc
commit
a8c70ed2b4
Notes:
git
2023-08-17 00:47:59 +00:00
@ -1076,6 +1076,22 @@ class ErrorsTest < Test::Unit::TestCase
|
||||
assert_errors expected, "def foo(a,b,&a);end", [
|
||||
["Duplicated parameter name.", 13..14]
|
||||
]
|
||||
|
||||
expected = DefNode(
|
||||
Location(),
|
||||
nil,
|
||||
ParametersNode([], [OptionalParameterNode(:a, Location(), Location(), IntegerNode())], [RequiredParameterNode(:b)], RestParameterNode(Location(), Location()), [], nil, nil),
|
||||
nil,
|
||||
[:a, :b, :c],
|
||||
Location(),
|
||||
nil,
|
||||
Location(),
|
||||
Location(),
|
||||
nil,
|
||||
Location()
|
||||
)
|
||||
|
||||
assert_errors expected, "def foo(a = 1,b,*c);end", [["Unexpected parameter *", 16..17]]
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -8312,6 +8312,10 @@ update_parameter_state(yp_parser_t *parser, yp_token_t *token, yp_parameters_ord
|
||||
return;
|
||||
}
|
||||
|
||||
if (token->type == YP_TOKEN_USTAR && *current == YP_PARAMETERS_ORDER_AFTER_OPTIONAL) {
|
||||
yp_diagnostic_list_append(&parser->error_list, token->start, token->end, "Unexpected parameter *");
|
||||
}
|
||||
|
||||
if (*current == YP_PARAMETERS_ORDER_NOTHING_AFTER || state > *current) {
|
||||
// We know what transition we failed on, so we can provide a better error here.
|
||||
yp_diagnostic_list_append(&parser->error_list, token->start, token->end, "Unexpected parameter order");
|
||||
|
Loading…
x
Reference in New Issue
Block a user