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

Method sorting bug #12580

Closed
timholy opened this issue Aug 12, 2015 · 2 comments
Closed

Method sorting bug #12580

timholy opened this issue Aug 12, 2015 · 2 comments
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@timholy
Copy link
Member

timholy commented Aug 12, 2015

With these types:

abstract Paint{T, N}

# AbstractColor means just color, no transparency
abstract AbstractColor{T, N} <: Paint{T, N}
abstract Color{T}            <: AbstractColor{T, 3}
abstract AbstractRGB{T}      <: Color{T}
abstract AbstractGray{T}     <: AbstractColor{T, 1}

immutable RGB{T} <: AbstractRGB{T}
    r::T # Red [0,1]
    g::T # Green [0,1]
    b::T # Blue [0,1]
end

# Types with transparency
abstract Transparent{C<:AbstractColor,T,N} <: Paint{T,N}
abstract AbstractColorAlpha{C,T,N} <: Transparent{C,T,N}
immutable ColorAlpha{C<:Color,T} <: AbstractColorAlpha{C,T,4}
    c::C
    alpha::T
end

typealias RGBA{T} ColorAlpha{RGB{T},T}

and these methods:

colortype{C<:AbstractColor    }(::Type{C})                  = C
colortype{C<:AbstractColor    }(::Type{Transparent{C}})     = C
colortype{C<:AbstractColor,T  }(::Type{Transparent{C,T}})   = C
colortype{C<:AbstractColor,T,N}(::Type{Transparent{C,T,N}}) = C
colortype{P<:Transparent}(::Type{P}) = colortype(super(P))

then colortype(RGBA{Float32}) == RGB{Float32} as desired. But in this order:

colortype{C<:AbstractColor    }(::Type{C})                  = C
colortype{P<:Transparent}(::Type{P}) = colortype(super(P))
colortype{C<:AbstractColor    }(::Type{Transparent{C}})     = C
colortype{C<:AbstractColor,T  }(::Type{Transparent{C,T}})   = C
colortype{C<:AbstractColor,T,N}(::Type{Transparent{C,T,N}}) = C

it yields:

ERROR: MethodError: `colortype` has no method matching colortype(::Type{Paint{Float32,4}})
 in colortype at none:1
...
@mauro3
Copy link
Contributor

mauro3 commented Nov 25, 2016

Note that this is fixed with #18457.

I think this is a smaller repo (also fixed in #18457):

# doesn't work on 0.5 (but works on jb/subtypes):
abstract AbstractMyType{T}
immutable MyType{T}<:AbstractMyType{T} end
tpara{A<:AbstractMyType}(::Type{A}) = (print(1); println(" ", A, " ", supertype(A)); tpara(supertype(A)))
tpara{I}(::Type{AbstractMyType{I}}) = (println(2); I)
tpara(MyType{true})

# julia> tpara(MyType{true})
# 1 MyType{true} AbstractMyType{true}
# 1 AbstractMyType{true} Any
# ERROR: MethodError: no method matching tpara(::Type{Any})
# Closest candidates are:
#   tpara{A<:AbstractMyType{T}}(::Type{A<:AbstractMyType}) at REPL[3]:1
#   tpara{I}(::Type{AbstractMyType{I}}) at REPL[4]:1
#  in tpara(::Type{MyType{true}}) at ./REPL[3]:1

# works:
abstract AbstractMyType{T}
immutable MyType{T}<:AbstractMyType{T} end
tpara{I}(::Type{AbstractMyType{I}}) = (println(2); I) # swap method order to make it workL
tpara{A<:AbstractMyType}(::Type{A}) = (print(1); println(" ", A, " ", supertype(A)); tpara(supertype(A)))
tpara(MyType{true})

@JeffBezanson
Copy link
Member

closed by #18457

@vtjnash vtjnash mentioned this issue Jan 16, 2017
53 tasks
mauro3 added a commit to mauro3/julia that referenced this issue Jan 17, 2017
mauro3 added a commit to mauro3/julia that referenced this issue Jan 17, 2017
mauro3 added a commit to mauro3/julia that referenced this issue Jan 17, 2017
mauro3 added a commit to mauro3/julia that referenced this issue Jan 17, 2017
mauro3 added a commit to mauro3/julia that referenced this issue Jan 18, 2017
Added tests for issues JuliaLang#12580, JuliaLang#18348, JuliaLang#13165, JuliaLang#11803, JuliaLang#12721

Enabled extra tests for JuliaLang#11840, however, that isssue is not resolved
yet but needs tests triggering it.
mauro3 added a commit to mauro3/julia that referenced this issue Jan 20, 2017
Added tests for issues JuliaLang#12580, JuliaLang#18348, JuliaLang#13165, JuliaLang#12721

For JuliaLang#11803 it was decidided that no tests are needed.

Enabled extra tests for JuliaLang#11840, however, that isssue is not resolved
yet but needs new tests triggering it.
mauro3 added a commit to mauro3/julia that referenced this issue Jan 20, 2017
Added tests for issues JuliaLang#12580, JuliaLang#18348, JuliaLang#13165, JuliaLang#12721

For JuliaLang#11803 it was decidided that no tests are needed.

Enabled extra tests for JuliaLang#11840, however, that isssue is not resolved
yet but needs new tests triggering it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

4 participants