I'm not sure if this should work or not, but I'm surprised by the result:
julia> f(::Type{Union{X,Y}}) where {X,Y} = (X,Y)
f (generic function with 1 method)
julia> f(Union{Int64, Float64})
ERROR: UndefVarError: Y not defined
Stacktrace:
[1] f(::Type{Union{Float64, Int64}}) at ./REPL[2]:1
[2] top-level scope at none:0
julia> @code_warntype f(Union{Int64, Float64})
Body::Tuple{Type,Any}
1 1 ─ %1 = (Core.tuple)($(Expr(:static_parameter, 1)), $(Expr(:static_parameter, 2)))::Tuple{Type,Any}
└── return %1
All of those answers and results look correct to me
Could you expand on that? I would expect that either the type variables are bound or the method is uncallable. Are there other situations that can produce undef type variables?
Yes. Actually, prior to v0.7 we did make methods uncallable if we couldn't determine type variable values, but we found that too complicated since applicability had an extra condition aside from just subtyping. You can also get undefined type variables in a case like:
f(x, y::Vararg{T}) where {T} = ...
If this function is called with 1 argument, T is undefined.
Most helpful comment
Yes. Actually, prior to v0.7 we did make methods uncallable if we couldn't determine type variable values, but we found that too complicated since applicability had an extra condition aside from just subtyping. You can also get undefined type variables in a case like:
If this function is called with 1 argument,
Tis undefined.