-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Dispatch broken for containers of objects parametrized with TypeVars #12596
Comments
It's actually the 2nd parameter that's causing the problem, and it depends on whether it's a bound or unbound typevar. Reduced case: abstract AbstractColor{T, N}
abstract Color{T} <: AbstractColor{T, 3}
abstract Transparent{C<:AbstractColor,T,N}
immutable RGB{T<:FloatingPoint} <: Color{T}
r::T # Red [0,1]
g::T # Green [0,1]
b::T # Blue [0,1]
end
C = TypeVar(:C,AbstractColor,true)
Tu = TypeVar(:T,false)
Tb = TypeVar(:T,true)
N = TypeVar(:N,true)
B = Transparent{C,Tb,N}
julia> P = Transparent{RGB{Tu},Tu,4}
Transparent{RGB{T},T,4}
julia> typeintersect(Type{P}, Type{B})
Union{}
julia> P = Transparent{RGB{Tu},Tb,4}
Transparent{RGB{T},T,4}
julia> typeintersect(Type{P}, Type{B})
Type{Transparent{RGB{T},T,4}} The key lines seem to be here. This may give me enough guidance to work around this. |
Sounds like #2552 (comment) and/or #11597. I've actually stopped restricting type parameters in my own code and just enforcing it by what constructors I provide because of wonkiness like this and because I often want "triangular" constraints which aren't expressible in any case. |
Yeah, this indeed popped up in a rework of Color.jl, for which I'm trying to design some nice traits to compensate for the lack of triangular dispatch. It specifically arose through introspection on |
Rearing its head again. Here's a simple real-world example: julia> abstract A{T,N}
julia> immutable B{T} <: A{T,3}
val::T
end
julia> len{T,N}(::Type{A{T,N}}) = N
len (generic function with 1 method)
julia> super(B)
A{T,3}
julia> len(super(B))
ERROR: MethodError: `len` has no method matching len(::Type{A{T,3}}) This seems to be a consequence of fixing #7062. I have to say, this seems like a worse problem to have than #7062. What do you think, @vtjnash? |
Just to show you how devious I am (in case you had any remaining doubts), here's a workaround: julia> len2{N}(::Type{A{TypeVar(:T),N}}) = N
len2 (generic function with 1 method)
julia> len2(super(B))
3 |
that answer looks correct to me. the TypeVar |
I wonder whether this issue should turn into "further disambiguate the printing of method tables and types so the proper dispatch rules are obvious"? |
closed by #18457 |
Maybe I'm just not seeing it, but to me this seems to be a bug:
Yet
The text was updated successfully, but these errors were encountered: