From 30d50030a3b7a88516143bbfd60aadccafefdbfe Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Sat, 29 Aug 2020 18:59:47 +0200 Subject: [PATCH] Fix type-equality involving `Type{Union{}}` (#37261) In particular, make `obviously_unequal(Type{Union{}}, Type{T} where {Union{}<:T<:Union{}})` false. Fixes #37255 (cherry picked from commit 79a9ea08c7ebe915af1f669b498c61a1d88b42c0) --- src/subtype.c | 4 ++++ test/subtype.jl | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/subtype.c b/src/subtype.c index 4aadeef3404408..260252fe3d2ddd 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -235,6 +235,10 @@ static int obviously_unequal(jl_value_t *a, jl_value_t *b) if (jl_is_datatype(b)) { jl_datatype_t *ad = (jl_datatype_t*)a; jl_datatype_t *bd = (jl_datatype_t*)b; + if (a == (jl_value_t*)jl_typeofbottom_type && bd->name == jl_type_typename) + return obviously_unequal(jl_bottom_type, jl_tparam(bd, 0)); + if (ad->name == jl_type_typename && b == (jl_value_t*)jl_typeofbottom_type) + return obviously_unequal(jl_tparam(ad, 0), jl_bottom_type); if (ad->name != bd->name) return 1; int istuple = (ad->name == jl_tuple_typename); diff --git a/test/subtype.jl b/test/subtype.jl index 61dbdaa4db7c22..265be9981d3202 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1767,3 +1767,6 @@ end # issue #37180 @test !(typeintersect(Tuple{AbstractArray{T}, VecOrMat{T}} where T, Tuple{Array, Any}).body.parameters[1] isa Union) + +# issue #37255 +@test Type{Union{}} == Type{T} where {Union{}<:T<:Union{}}