-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disallow duplicate argument names #742
Comments
I agree with you. $ ruby -v
ruby 3.3.2 (2024-05-30 revision e5a195edf6) [arm64-darwin22]
## required_positional
$ ruby -we 'def foo(a, a) = 1'
-e:1: duplicated argument name
def foo(a, a) = 1
-e: compile error (SyntaxError)
## required_keyword
$ ruby -we 'def foo(a:, a:) = 1'
-e:1: duplicated argument name
def foo(a:, a:) = 1
-e: compile error (SyntaxError)
## positional_keyword
$ ruby -we 'def foo(a, a:) = 1'
-e:1: duplicated argument name
def foo(a, a:) = 1
-e: compile error (SyntaxError) It seems that Hash report a warning when keys are duplicated.
|
I was about to suggest Syntax Error, but then I remembered #1639. a = {key: value}
b = {key: a, **a} #=> {key: value}, no warning |
I implemented duplicate argument checking and found duplicates in the following methods in the rbs repository.
|
Currently RBS allows duplicate argument names.
It conceals mistakes, like ruby/gem_rbs_collection#50.
I'm 100% sure that RBS should reject duplicate keyword argument names. Kwargs are represented as a Hash, which uses argument names as hash keys, so duplicated kwarg names are completely meaningless.
But RBS can distinguish duplicate names in other cases, and it will introduce language change if we fix the problem. So I'm not 100% sure, but it will be useful if RBS reject duplicate argument names for all cases.
The text was updated successfully, but these errors were encountered: