convert fails for parametric type unions, e.g.
julia> immutable TC{T} end
julia> immutable TD{T} end
julia> typealias TCD{T} Union(TC{T}, TD{T})
Union(TC{T},TD{T})
julia> convert{T}(::Type{TCD{T}}, x::TC) = "Andreas"
convert (generic function with 493 methods)
julia> convert(TCD{Float64}, TC{Float64}())
TC{Float64}()
julia> convert(TCD{Float64}, TC{Float32}())
ERROR: `convert` has no method matching
convert(::Type{Union(TD{Float64},TC{Float64})}, ::TC{Float32})
Closest candidates are:
convert(::Type{T}, ::T)
convert(::Type{Nullable{T}}, ::T)
convert(::Type{Union(TC{T},TD{T})}, ::TC{T})
but I can define convert methods for non-parametric type unions, e.g.
julia> immutable TA end
julia> immutable TB end
julia> typealias TAB Union(TA, TB)
Union(TA,TB)
julia> import Base.convert
julia> convert(::Type{TAB}, x::TA) = "Andreas"
convert (generic function with 493 methods)
julia> convert(TAB, TA())
"Andreas"
and it also works fine for abstract types
julia> abstract TEF{T}
julia> immutable TE{T} <: TEF{T} end
julia> immutable TF{T} <: TEF{T} end
julia> convert{T}(::Type{TEF{T}}, TE) = "Andreas"
convert (generic function with 494 methods)
julia> convert(TEF{Float64}, TE{Float32}())
"Andreas"
Is this a limitation to parametric unions or is it a bug?