-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 fun
parameter names
#11967
Disallow duplicate fun
parameter names
#11967
Conversation
args.each do |arg| | ||
if arg.name == arg_name | ||
raise "duplicated fun parameter name: #{arg_name}", arg_location | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if using each is an optimization but isn't there a built in method for this?
args.each do |arg| | |
if arg.name == arg_name | |
raise "duplicated fun parameter name: #{arg_name}", arg_location | |
end | |
end | |
if args.includes?(arg_name) | |
raise "duplicated fun parameter name: #{arg_name}", arg_location | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would need to do something like:
if args.any? &.name.==(arg_name)
raise "duplicated fun parameter name: #{arg_name}", arg_location
end
since args
is an array of objects and not just a simple array of strings or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from the check for defs which also needed to look at the external parameter names (any?
would require two iterations as the error messages are different).
I don't think any?
here is necessarily cleaner than the current approach.
The following fails during codegen:
Having two
x
s is not allowed for defs anyway, so it makes sense the same should apply to funs, including lib funs which have no body, as named argument passing only behaves properly when all the parameters have unique names.