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

Missing ambiguity error for diagonal dispatch #20672

Closed
yuyichao opened this issue Feb 19, 2017 · 7 comments
Closed

Missing ambiguity error for diagonal dispatch #20672

yuyichao opened this issue Feb 19, 2017 · 7 comments
Labels
domain:types and dispatch Types, subtyping and method dispatch

Comments

@yuyichao
Copy link
Contributor

I mentioned this in #20056 (comment) but looking at it again, I think it's probably unrelated/significantly different.

A simpler example for it is

julia> f(::Real, ::Real) = 1
f (generic function with 1 method)

julia> f{T}(::T, ::T) = 2
f (generic function with 2 methods)

julia> f(1, 1)
1

Since the two methods matches two intersecting sets, the intersection should be ambiguous.

A similar case was brought up in #20078 (comment) where Jeff proposed treating explicitly specified leaftype specially though it doesn't really apply to the case here.

@yuyichao yuyichao added the domain:types and dispatch Types, subtyping and method dispatch label Feb 19, 2017
@vtjnash
Copy link
Sponsor Member

vtjnash commented Feb 19, 2017

Looks correct to me: Real <: Any

@andyferris
Copy link
Member

What? No, in the former they can be different leaf types, but not the latter (unless that changed?). Neither signature is a subset of (ie more specific than) the other, but both match f(1,1).

@vtjnash
Copy link
Sponsor Member

vtjnash commented Feb 19, 2017

A ∩ B ≠ ø ↛ ambiguity. All that's required is that A > B && B > C && A ∩ C ≠ ø → A > C (aka transitivity)

@yuyichao
Copy link
Contributor Author

What's C?

@StefanKarpinski
Copy link
Sponsor Member

This is a little cryptic. Does the first statement mean that A ∩ B ≠ ø implies no ambiguity or that it does not imply ambiguity? Regarding the second statement, as @yuyichao said, what's C?

@JeffBezanson
Copy link
Sponsor Member

This is very similar to #3025. If specificity is limited to strict subtypes, then yes these are technically ambiguous. However I'm inclined to allow (Real,Real) to be more specific than (T,T), since the former definition presumably knows something about real numbers, while the latter definition is for any type at all (as long as you pass two things of the same type). Generally, declared sub-classes take priority over other aspects of types; for example Array is more specific than AbstractArray{Int}.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 8, 2019

yes, this example was a bit simpler, but it's the same result & not a bug

@vtjnash vtjnash closed this as completed Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

5 participants