Dispatch broken for containers of objects parametrized with TypeVars #12596
Closed
Description
Maybe I'm just not seeing it, but to me this seems to be a bug:
abstract Paint{T, N}
abstract AbstractColor{T, N} <: Paint{T, N}
abstract Color{T} <: AbstractColor{T, 3}
abstract Transparent{C<:AbstractColor,T,N} <: Paint{T,N}
immutable RGB{T<:FloatingPoint} <: Color{T}
r::T # Red [0,1]
g::T # Green [0,1]
b::T # Blue [0,1]
end
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
T = TypeVar(:T)
colortype(RGB{Float32}) # yields RGB{Float32}
colortype(RGB) # yields RGB{T<:FloatingPoint}
colortype(RGB{T}) # yields RGB{T}
P = Transparent{RGB{Float32},Float32,4}
colortype(P) # yields RGB{Float32}
P = Transparent{RGB{T},T,4}
julia> colortype(P)
ERROR: LoadError: MethodError: `colortype` has no method matching colortype(::Type{Transparent{RGB{T},T,4}})
in include at ./boot.jl:254
in include_from_node1 at ./loading.jl:264
while loading /tmp/color_trouble2.jl, in expression starting on line 25
Yet
C = TypeVar(:C,AbstractColor)
N = TypeVar(:N)
julia> typeintersect(P, Transparent{C,T,N})
Transparent{RGB{T},T,4}
julia> P <: Transparent{C,T,N}
true
Activity