[PRISM] Fix error message for duplicate parameter name
This commit is contained in:
parent
d7d59ea172
commit
cdb8d208c9
@ -166,7 +166,7 @@ errors:
|
||||
- PARAMETER_BLOCK_MULTI
|
||||
- PARAMETER_CIRCULAR
|
||||
- PARAMETER_METHOD_NAME
|
||||
- PARAMETER_NAME_REPEAT
|
||||
- PARAMETER_NAME_DUPLICATED
|
||||
- PARAMETER_NO_DEFAULT
|
||||
- PARAMETER_NO_DEFAULT_KW
|
||||
- PARAMETER_NUMBERED_RESERVED
|
||||
|
@ -7176,7 +7176,7 @@ pm_parser_parameter_name_check(pm_parser_t *parser, const pm_token_t *name) {
|
||||
if (pm_constant_id_list_includes(&parser->current_scope->locals, constant_id)) {
|
||||
// Add an error if the parameter doesn't start with _ and has been seen before
|
||||
if ((name->start < name->end) && (*name->start != '_')) {
|
||||
pm_parser_err_token(parser, name, PM_ERR_PARAMETER_NAME_REPEAT);
|
||||
pm_parser_err_token(parser, name, PM_ERR_PARAMETER_NAME_DUPLICATED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
||||
[PM_ERR_PARAMETER_BLOCK_MULTI] = { "multiple block parameters; only one block is allowed", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_PARAMETER_CIRCULAR] = { "parameter default value references itself", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_PARAMETER_METHOD_NAME] = { "unexpected name for a parameter", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_PARAMETER_NAME_REPEAT] = { "repeated parameter name", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_PARAMETER_NAME_DUPLICATED] = { "duplicated argument name", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_PARAMETER_NO_DEFAULT] = { "expected a default value for the parameter", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_PARAMETER_NO_DEFAULT_KW] = { "expected a default value for the keyword parameter", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_PARAMETER_NUMBERED_RESERVED] = { "%.2s is reserved for numbered parameters", PM_ERROR_LEVEL_SYNTAX },
|
||||
|
@ -1,3 +1,3 @@
|
||||
exclude(:test_call_op_asgn_keywords, "unknown")
|
||||
exclude(:test_kwsplat_block_order_op_asgn, "unknown")
|
||||
exclude(:test_call_op_asgn_keywords_mutable, "unknown")
|
||||
exclude(:test_kwsplat_block_order_op_asgn, "unknown")
|
||||
|
@ -5,7 +5,6 @@ exclude(:test_class_module, "unknown")
|
||||
exclude(:test_disallowed_class_variable, "unknown")
|
||||
exclude(:test_disallowed_gloal_variable, "unknown")
|
||||
exclude(:test_disallowed_instance_variable, "unknown")
|
||||
exclude(:test_duplicate_argument, "unknown")
|
||||
exclude(:test_dynamic_constant_assignment, "unknown")
|
||||
exclude(:test_else_without_rescue, "unknown")
|
||||
exclude(:test_embedded_rd_error, "unknown")
|
||||
|
@ -1,6 +1,6 @@
|
||||
exclude(:test_unicode_age_14_0, "unknown")
|
||||
exclude(:test_invalid_fragment, "unknown")
|
||||
exclude(:test_unicode_age_15_0, "unknown")
|
||||
exclude(:test_unescape, "unknown")
|
||||
exclude(:test_invalid_escape_error, "unknown")
|
||||
exclude(:test_invalid_fragment, "unknown")
|
||||
exclude(:test_unescape, "unknown")
|
||||
exclude(:test_unicode_age_14_0, "unknown")
|
||||
exclude(:test_unicode_age_15_0, "unknown")
|
||||
exclude(:test_unicode_age, "unknown")
|
||||
|
@ -9,19 +9,6 @@ exclude(:test_brace_after_literal_argument, "unknown")
|
||||
exclude(:test_dedented_heredoc_concatenation, "unknown")
|
||||
exclude(:test_dedented_heredoc_continued_line, "unknown")
|
||||
exclude(:test_dedented_heredoc_invalid_identifer, "unknown")
|
||||
exclude(:test_duplicated_arg, "unknown")
|
||||
exclude(:test_duplicated_kw_kwrest, "unknown")
|
||||
exclude(:test_duplicated_kw, "unknown")
|
||||
exclude(:test_duplicated_opt_kw, "unknown")
|
||||
exclude(:test_duplicated_opt_kwrest, "unknown")
|
||||
exclude(:test_duplicated_opt_post, "unknown")
|
||||
exclude(:test_duplicated_opt_rest, "unknown")
|
||||
exclude(:test_duplicated_opt, "unknown")
|
||||
exclude(:test_duplicated_rest_kw, "unknown")
|
||||
exclude(:test_duplicated_rest_kwrest, "unknown")
|
||||
exclude(:test_duplicated_rest_opt, "unknown")
|
||||
exclude(:test_duplicated_rest_post, "unknown")
|
||||
exclude(:test_duplicated_rest, "unknown")
|
||||
exclude(:test_duplicated_when, "unknown")
|
||||
exclude(:test_error_message_encoding, "unknown")
|
||||
exclude(:test_heredoc_cr, "unknown")
|
||||
|
@ -1149,7 +1149,7 @@ module Prism
|
||||
)
|
||||
|
||||
assert_errors expected, "def foo(a,b,a);end", [
|
||||
["repeated parameter name", 12..13]
|
||||
["duplicated argument name", 12..13]
|
||||
]
|
||||
end
|
||||
|
||||
@ -1169,7 +1169,7 @@ module Prism
|
||||
)
|
||||
|
||||
assert_errors expected, "def foo(a,b,*a);end", [
|
||||
["repeated parameter name", 13..14]
|
||||
["duplicated argument name", 13..14]
|
||||
]
|
||||
|
||||
expected = DefNode(
|
||||
@ -1188,7 +1188,7 @@ module Prism
|
||||
)
|
||||
|
||||
assert_errors expected, "def foo(a,b,**a);end", [
|
||||
["repeated parameter name", 14..15]
|
||||
["duplicated argument name", 14..15]
|
||||
]
|
||||
|
||||
expected = DefNode(
|
||||
@ -1207,7 +1207,7 @@ module Prism
|
||||
)
|
||||
|
||||
assert_errors expected, "def foo(a,b,&a);end", [
|
||||
["repeated parameter name", 13..14]
|
||||
["duplicated argument name", 13..14]
|
||||
]
|
||||
|
||||
expected = DefNode(
|
||||
@ -1482,7 +1482,7 @@ module Prism
|
||||
def test_shadow_args_in_block
|
||||
source = "tap{|a;a|}"
|
||||
assert_errors expression(source), source, [
|
||||
["repeated parameter name", 7..8],
|
||||
["duplicated argument name", 7..8],
|
||||
]
|
||||
end
|
||||
|
||||
@ -1491,7 +1491,7 @@ module Prism
|
||||
# In Ruby 3.0.x, `Ripper.sexp_raw` does not return `nil` for this case.
|
||||
compare_ripper = RUBY_ENGINE == "ruby" && (RUBY_VERSION.split('.').map { |x| x.to_i } <=> [3, 1]) >= 1
|
||||
assert_errors expression(source), source, [
|
||||
["repeated parameter name", 14..15],
|
||||
["duplicated argument name", 14..15],
|
||||
], compare_ripper: compare_ripper
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user