Dispatching on the result of unwrap_unionall seems weird?

I’m pretty confused about the following dispatch behavior (Julia 1.1 and 1.2pre):

julia> foo(::Type{V}) where {V<:Vector} = @isdefined(V)
foo (generic function with 1 method)

julia> foo(Base.unwrap_unionall(Vector))
false

How can it be that we dispatch to foo, hence we’ve verified that V<:Vector, while simultaneously “not knowing what V is” since @isdefined(V) returns false?

This example seems fairly contrived, although I think its not hard to run into the effects of this (as I did) if you’re implementing custom printing for your types via e.g. specializing Base.show(io::IO, ::Type{MyType{Bar,Baz}}) where {Bar,Baz}, where you’ll get errors because Bar and Baz aren’t defined for the same reason as above.

1 Like