diff --git a/src/subtype.c b/src/subtype.c index b665d0dc49607..a5b99dc5440e5 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -1785,7 +1785,7 @@ jl_value_t *jl_type_intersection_matching(jl_value_t *a, jl_value_t *b, jl_svec_ // we assume that if the intersection is a leaf type, we have // full information in `env`. however the intersection algorithm // does not yet provide that in all cases so use subtype. - if (szb > 0 && jl_is_leaf_type(*ans)) { + if (szb > 0 && jl_is_leaf_type(*ans) && !jl_types_equal(b, (jl_value_t*)jl_type_type)) { if (jl_subtype_env(*ans, b, env, szb)) { for(i=0; i < sz; i++) { if (jl_is_typevar(env[i])) { diff --git a/test/subtype.jl b/test/subtype.jl index 6077152d01ffe..06287f3fbf4db 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -782,6 +782,11 @@ function test_intersection() @testintersect(DataType, Type, DataType) @testintersect(DataType, Type{T} where T<:Integer, Type{T} where T<:Integer) + @testintersect(Union{DataType,Int}, Type, DataType) + @testintersect(Union{DataType,Int}, Type{T} where T, DataType) + # test typeintersect wrapper as well as _type_intersect + @test typeintersect(Union{DataType,Int}, Type) === DataType + @test typeintersect(Union{DataType,Int}, Type{T} where T) === DataType @testintersect((Type{Tuple{Vararg{T}}} where T), Type{Tuple}, Bottom) @testintersect(Tuple{Type{S}, Tuple{Any, Vararg{Any}}} where S<:Tuple{Any, Vararg{Any}},