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

I can enter the same keyword argument twice, and the second over-rules the first #16937

Closed
colintbowers opened this issue Jun 15, 2016 · 4 comments
Assignees
Labels
breaking This change will break code compiler:lowering Syntax lowering (compiler front end, 2nd stage) error handling Handling of exceptions by Julia or the user
Milestone

Comments

@colintbowers
Copy link

colintbowers commented Jun 15, 2016

A short example:

f(x::Int ; kw::Int=0) = x * kw
f(2)
f(2, kw=3) #evaluates to 6
f(2, kw=3, kw=4) #evaluates to 8

I'm on v0.4, but I asked about it on the julia-users list here, and was told you can still do this in v0.5. The link also contains an argument for why this might be considered a feature and not a bug. Personally, it feels more like a bug to me - but I am a very small voice.

I stumbled onto this when typing out several keyword arguments, and my mind was still on the previous keyword as I typed the next one, and so I accidentally typed it twice. Easy to do, and it took me quite a while to work out where I'd gone wrong.

@JeffBezanson
Copy link
Member

It seems pretty reasonable to make this a syntax error.

@ivarne ivarne added the error handling Handling of exceptions by Julia or the user label Jun 15, 2016
@martinholters
Copy link
Member

As mentioned on the list, the current behavior might be useful with splatting for something like foo(;defaults..., overrides..) to work, but the same could be achieved with an explicit merge, of course.
Well, not exactly the same: If foo is defined as foo(;kwargs...), it can actually tell whether a value is given multiple times. This might be potentially useful if one actually wants to allow multiple values to one kwarg, but wants to avoid a collection for some reason E.g. process_file(input="foo.txt", input="bar.txt") could process both files. But this feels so fragile compared to "normal" kwarg behavior that I'm also in favor of making it a syntax error.

@ivarne
Copy link
Member

ivarne commented Jun 15, 2016

Somewhat relevant discussion in #4916

@toivoh
Copy link
Contributor

toivoh commented Jun 15, 2016 via email

@JeffBezanson JeffBezanson added the compiler:lowering Syntax lowering (compiler front end, 2nd stage) label Jun 15, 2016
@JeffBezanson JeffBezanson self-assigned this Apr 30, 2017
@JeffBezanson JeffBezanson added this to the 1.0 milestone Apr 30, 2017
@JeffBezanson JeffBezanson added the breaking This change will break code label Apr 30, 2017
JeffBezanson added a commit that referenced this issue May 17, 2017
give a syntax error for repeated keyword args. fixes #16937
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code compiler:lowering Syntax lowering (compiler front end, 2nd stage) error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

No branches or pull requests

5 participants