Weirdness of `Type{Union{A,B}} where {B<:SuperB}`

Here’s a breakdown to explain each of your examples:

julia> struct Foo end

julia> S = Union{Foo, T} where {T<:Base.IEEEFloat}
Union{Foo, T} where T<:Union{Float16, Float32, Float64}

julia> T = Type{S{T}} where {T<:Base.IEEEFloat}
Type{Union{Foo, T}} where T<:Union{Float16, Float32, Float64}

julia> Foo isa T  # the first query in the OP, `true` because the following is `true`:
true

julia> Type{Foo} == T{Union{}}  # `true` because the following is `true`:
true

julia> Foo == S{Union{}}
true

julia> Float32 isa T  # the second query in the OP, `false` because there is no `X` such that `Type{Float32} == T{X}`, which is because there is no `X` such that `Float32 == S{X}`
false

julia> Union{Foo, Float32} isa T  # the third query in the OP, `true` because the following is `true`:
true

julia> Type{Union{Foo, Float32}} == T{Float32}  # `true` because the following is `true`:
true

julia> Union{Foo, Float32} == S{Float32}
true
4 Likes