-
-
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
incorrect method sorting with union in typevar bound #8915
Labels
types and dispatch
Types, subtyping and method dispatch
Comments
This seems like a general method sorting bug not restricted to constructors: julia> type A{T} end
julia> f{T<:Union(Float64,Int)}(::Type{A{T}}, a) = false;
julia> f{T<:Union(Float64,Int)}(::Type{A{T}}, a::Int) = true;
julia> f(A{Float64}, 1)
false
julia> methods(f)
# 2 methods for generic function "f":
f{T<:Union(Float64,Int64)}(::Type{A{T<:Union(Float64,Int64)}},a) at none:1
f{T<:Union(Float64,Int64)}(::Type{A{T<:Union(Float64,Int64)}},a::Int64) at none:1 In this form it's reproducible on 0.3 as well. |
srp
changed the title
Constructor selection based off method order if type parameterized off Union
Method/constructor selection isn't working right
Nov 7, 2014
JeffBezanson
changed the title
Method/constructor selection isn't working right
incorrect method sorting with union in typevar bound
Nov 7, 2014
Another likely instance of this can be seen in ColorTypes, depending on whether we precompile or not: tim@diva:~/.julia/v0.5/ColorTypes/test$ julia -q
julia> using ColorTypes
julia> Gray(0.8)
Gray{Float64}(0.8)
julia>
tim@diva:~/.julia/v0.5/ColorTypes/test$ julia -q
julia> include("../src/ColorTypes.jl")
ColorTypes
julia> using ColorTypes
julia> Gray(0.8)
------------------------------------------------------------------------------------------
StackOverflowError Stacktrace (most recent call last)
[#1] — ColorTypes.Gray{T<:Union{AbstractFloat,Bool,FixedPointNumbers.FixedPoint}}(::Float64)
⌙ at types.jl:369 (repeats 80000 times)
StackOverflowError: |
closed by #18457 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The documentation states that methods are selected based off which is the most specific. While not explicitly stated, this generally also seems to be true of constructors. However on 0.4, the following seems to be functioning off the order the constructors are declared in, rather then which is most specific:
Which produces the following output:
I can't reproduce this on 0.3, only 0.4. I've also only been able to reproduce this when parameterizing the type with a Union.
The text was updated successfully, but these errors were encountered: