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

ambiguity warning missing? #3025

Closed
vtjnash opened this issue May 5, 2013 · 8 comments
Closed

ambiguity warning missing? #3025

vtjnash opened this issue May 5, 2013 · 8 comments
Assignees
Labels
docs This change adds or pertains to documentation types and dispatch Types, subtyping and method dispatch

Comments

@vtjnash
Copy link
Sponsor Member

vtjnash commented May 5, 2013

julia> function z(a::(Integer,Integer)...)
       println(4)
       end
# methods for generic function z
z(a::(Integer,Integer)...) at none:2

julia> function z{T}(a::(T,T)...)
       println(5)
       end
# methods for generic function z
z(a::(Integer,Integer)...) at none:2
z{T}(a::(T,T)...) at none:2

julia> z((1,2),(3,int32(3))) #good
4

julia> z((1,2),(3,3)) #oops, expecting 5
4

julia> function z{T<:Integer}(a::(T,T)...)
       println(6)
       end

julia> z((1,2),(3,4)) # ok, that's better but why?
6
@JeffBezanson
Copy link
Sponsor Member

Arguably, the 4 and 5 definitions are ambiguous.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented May 6, 2013

If they are ambiguous, shouldn't there be a warning that 6 is needed?

Simpler demonstration of above:

julia> z{T}(x::T, y::T) = 1
# methods for generic function z
z{T}(x::T,y::T) at none:1

julia> z(x::Integer, y::Integer) = 2
# methods for generic function z
z(x::Integer,y::Integer) at none:1
z{T}(x::T,y::T) at none:1

julia> z(1,int32(2)) # good
2

julia> z(1,2) # maybe not?
2

@JeffBezanson
Copy link
Sponsor Member

Well, I do really think they are ambiguous. One is specialized for integers and the other accepts any type, but is more specific in that the arguments need to be the same type.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented May 6, 2013

title updated to reflect possible issue

@StefanKarpinski
Copy link
Sponsor Member

From triage: this is now believed to actually be correct behavior; should be documented.

@StefanKarpinski StefanKarpinski added the docs This change adds or pertains to documentation label Jul 6, 2017
@JeffBezanson
Copy link
Sponsor Member

JeffBezanson commented Jul 6, 2017

Example:

julia> zz{T<:Integer}(x::T, y::T) = 1

julia> zz(x::Integer, y::Integer) = 2

julia> zz{T}(x::T, y::T) = 3

julia> methods(zz)
# 3 methods for generic function "zz":
[1] zz(x::T, y::T) where T<:Integer in Main at REPL[8]:1
[2] zz(x::Integer, y::Integer) in Main at REPL[9]:1
[3] zz(x::T, y::T) where T in Main at REPL[11]:1

The current thinking is that this sorting is correct, since mentioning Integer should be more specific than T<:Any. In turn, both specifying Integer and a diagonal constraint is even more specific.

@StefanKarpinski
Copy link
Sponsor Member

StefanKarpinski commented Jul 11, 2017

In case it's unclear to anyone, methods prints methods in specificity order, so the above shows that the methods are defined in order of most to least specific.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Jul 8, 2019

doc issue is #23740. method sort ordering is consistent, so there's no 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
docs This change adds or pertains to documentation types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants