Skip to content
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

Display argument that is duplicated in function calls #35857

Merged
merged 7 commits into from
May 15, 2020

Conversation

ssikdar1
Copy link
Contributor

Description

Fixes #34084

Now error message will also give the name of a variable duplicated in the function call.

Testing

julia> foo !== foo = bar
ERROR: syntax: function argument name not unique: foo around REPL[1]:1
Stacktrace:
 [1] top-level scope at REPL[1]:1
julia> function lala(;  bar=3, bar=4, boo=5)
       end
ERROR: syntax: function argument name not unique: bar around REPL[2]:1
Stacktrace:
 [1] top-level scope at REPL[2]:1

@ssikdar1
Copy link
Contributor Author

ssikdar1 commented May 12, 2020

Seems some doctests / tests need to be modified, I can do that if the change to error message is acceptable?

@@ -335,11 +335,12 @@
(optional-positional-defs name sparams req opt dfl body
(append req opt vararg) rett)))))
;; no optional positional args
(let ((names (map car sparams))
(let* ((names (map car sparams))
(anames (map (lambda (x) (if (underscore-symbol? x) UNUSED x))
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix the indenting here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation fixed 5126389

src/julia-syntax.scm Outdated Show resolved Hide resolved
@JeffBezanson
Copy link
Sponsor Member

I think we usually quote variable names in error messages, so how about Function argument name "x" not unique.

@ssikdar1
Copy link
Contributor Author

I think we usually quote variable names in error messages, so how about Function argument name "x" not unique.
kk! Added in d10dfbb and unit test fixed in 7d17ada

(if (has-dups (filter (lambda (x) (not (eq? x UNUSED))) anames))
(error "function argument names not unique"))
(let* ((names (map car sparams))
(anames (map (lambda (x) (if (underscore-symbol? x) UNUSED x))(llist-vars argl)))
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(anames (map (lambda (x) (if (underscore-symbol? x) UNUSED x))(llist-vars argl)))
(anames (map (lambda (x) (if (underscore-symbol? x) UNUSED x)) (llist-vars argl)))

Plus the indentation is still wrong --- the start of each (var value) pair in the let* should line up. Any good code editor should have a scheme mode that does this automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, was using vi to edit the file. Used sublime editor to do the indentation automatically and added the space in suggestion in 02a087a

@JeffBezanson JeffBezanson merged commit 759e78c into JuliaLang:master May 15, 2020
@JeffBezanson
Copy link
Sponsor Member

Thanks for taking the time to fix this up. Appreciated!

@ssikdar1 ssikdar1 deleted the dup-args branch May 15, 2020 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"syntax: function argument names not unique"-error could give the argument(s) that is(are) duplicated
2 participants