Skip to content

Commit

Permalink
[PRISM] Fix error message for duplicate parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Mar 29, 2024
1 parent d7d59ea commit cdb8d20
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion prism/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion prism/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion prism/templates/src/diagnostic.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion test/.excludes-prism/TestCall.rb
Original file line number Diff line number Diff line change
@@ -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")
1 change: 0 additions & 1 deletion test/.excludes-prism/TestParse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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")
Expand Down
6 changes: 3 additions & 3 deletions test/.excludes-prism/TestRegexp.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exclude(:test_unicode_age_14_0, "unknown")
exclude(:test_invalid_escape_error, "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_unicode_age_14_0, "unknown")
exclude(:test_unicode_age_15_0, "unknown")
exclude(:test_unicode_age, "unknown")
13 changes: 0 additions & 13 deletions test/.excludes-prism/TestSyntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@
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")
Expand Down
12 changes: 6 additions & 6 deletions test/prism/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ def test_duplicated_parameter_names
)

assert_errors expected, "def foo(a,b,a);end", [
["repeated parameter name", 12..13]
["duplicated argument name", 12..13]
]
end

Expand All @@ -1169,7 +1169,7 @@ def test_duplicated_parameter_names
)

assert_errors expected, "def foo(a,b,*a);end", [
["repeated parameter name", 13..14]
["duplicated argument name", 13..14]
]

expected = DefNode(
Expand All @@ -1188,7 +1188,7 @@ def test_duplicated_parameter_names
)

assert_errors expected, "def foo(a,b,**a);end", [
["repeated parameter name", 14..15]
["duplicated argument name", 14..15]
]

expected = DefNode(
Expand All @@ -1207,7 +1207,7 @@ def test_duplicated_parameter_names
)

assert_errors expected, "def foo(a,b,&a);end", [
["repeated parameter name", 13..14]
["duplicated argument name", 13..14]
]

expected = DefNode(
Expand Down Expand Up @@ -1482,7 +1482,7 @@ def test_shadow_args_in_lambda
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

Expand All @@ -1491,7 +1491,7 @@ def test_repeated_parameter_name_in_destructured_params
# 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

Expand Down

0 comments on commit cdb8d20

Please sign in to comment.