-
-
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
Unnecessary ambiguity warning? #5460
Comments
It's not truly ambiguous, but I should think that it might be a bit tricky to detect this in the ambiguity detection machinery (Jeff will have to say whether this is within reach).
since one of the four first |
Good suggestion. @JeffBezanson, if this is hard to fix, I propose we just add this to the FAQ (or someplace). |
As I read it, f(Any, union(A,B)) and f(union(A,B),Any) is exactly the situation mentioned in http://docs.julialang.org/en/release-0.2/manual/methods/#method-ambiguities and, since Any can match more than A and B the other methods that have been defined are insufficient to remove that ambiguity. |
The ambiguous case would be |
It was just a reply to @timholy suggesting that its already covered in the manual (though of course it can't hurt to repeat common problems in the FAQs sometimes). Inferring the method taking unions would hide the ambiguity, which in your case is your intention, but it may also infer methods that hide accidental ambiguities, which I would argue is a bad thing, especially in more subtle situations than the plain two argument Any situation here. Adding the one liner you suggested tells Julia your intentions. [pao: fix spelling of @timholy's username] |
Closed by #16125 |
This yields
Is this truly ambiguous, since I've already defined
myfunc
for any combination of typesA
andB
?In my real-life implementation, defining
myfunc(obj1::Union(A,B),obj2::Union(A,B))
will lead to a circular call, since it will dispatch to one of the specific instances.The text was updated successfully, but these errors were encountered: