-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Keyword arguments affect methods dispatch #9498
Comments
see also #4469 (comment) |
I think we should add keyword arguments to the calling convention, replacing the existing Currently, defining a keyword method actually defines three methods:
My proposal merges methods (2) and (3):
It would be possible to get the performance aspect of this just by passing a different kind of container to our existing kwsorter, and changing its lowering to make it easier to specialize. However our current implementation is also very complex, and we'd still need a separate fix for the semantic issue described here. Having 2 methods instead of 3 will also make reflection easier. So I think this redesign should be considered. |
This shouldn't have been closed, yet, I guess. Or did I miss something? |
Will have to punt on this for 1.0. |
Added an example of issue JuliaLang#9498 - since it is not scheduled to be fixed until Julia 2.0. Kept the example of ambiguous/last-seen default code being run because that is the core use case for default values.
Not sure why this worked before JuliaLang#37461, perhaps JuliaLang#9498?
Can this behavior be seen as a bug? Then fixing it is not a breaking change. |
I'm pretty sure this is a bug, where should one starts to fix this? |
A path to fixing this would be making a PR that fixes it and running nanosoldier to see how much folks depend on this strange behavior. |
"in order to fix it you just fix it"? I think myself from 12 months ago was asking which file should I change to actually fix it, not the logistics after fixing it. There's a fair chance this is way above my ability grade, if anyone knows how and doesn't have time to elaborate, please just fix it, this seems pretty bad we didn't treat it with urgency for 9 years. |
Oh, lol, my bad. I was thinking about the social and ecosystem factors, not technical. |
This should be considered a correctness bug |
There are actually functions in Line 1724 in bee75f7
does not support keyword arguments. That Line 991 in bee75f7
kicks in. Same for |
So this is an issue that I find after figuring out how the keyword arguments are currently implemented in Julia. It will probably not be an issue anymore if #2773 is implemented.
The document on methods says
However, method dispatch actually behaves differently when doing a function call with or without keyword arguments. i.e.
What happens here is that
f.env.kwsorter
only has one method defined and therefore when calling with keyword argument,f(::Integer)
does not participate in method dispatch.IMHO, there are several possible ways to fix it,
Fix the document to include this behavior. This should be the easiest fix but will probably make the whole keyword argument/optional argument/multiple dispatch more confusing especially for someone who does not know how it all works behind the scene. (It's already quite confusing/surprising that anonymous function does not support keyword argument for someone (like me) that expects python-like keyword argument implementation.)
Having an entry (that just throw an error) in
env.kwsorter
even for methods that does not take keyword arguments. This can also avoid the following confusing abuse of overriding methodThis is probably the easiest way to fix the code and is consistent with the best long term behavior.
Fix Keyword arguments for anonymous functions #2773 and let the method themselves handle keyword argument dispatch. Since Keyword arguments for anonymous functions #2773 is on
1.0
milestone, hopefully this will be eventually be implemented.The text was updated successfully, but these errors were encountered: