Skip to content

Commit 63e5553

Browse files
KenoKristofferC
authored andcommitted
Make isdispatchtuple consistent for typeof(Union{}) (#45348)
We have `typeof(Union{}) == Type{Union{}}`, but were treating them differently in the calculation of `isdispatchtuple`. The compiler expects `isdispatchtuple` to commute with type equality in various places, so try to make this consistent. Fixes #45347 (cherry picked from commit a37dd16)
1 parent 6368fdc commit 63e5553

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/jltypes.c

+1
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,7 @@ void jl_precompute_memoized_dt(jl_datatype_t *dt, int cacheable)
11991199
if (dt->isdispatchtuple) {
12001200
dt->isdispatchtuple = jl_is_datatype(p) &&
12011201
((!jl_is_kind(p) && ((jl_datatype_t*)p)->isconcretetype) ||
1202+
(p == (jl_value_t*)jl_typeofbottom_type) || // == Type{Union{}}, so needs to be consistent
12021203
(((jl_datatype_t*)p)->name == jl_type_typename && !((jl_datatype_t*)p)->hasfreetypevars));
12031204
}
12041205
if (istuple && dt->has_concrete_subtype) {

test/subtype.jl

+5
Original file line numberDiff line numberDiff line change
@@ -1982,3 +1982,8 @@ end
19821982
@test_throws TypeError(:typeassert, Type, Vararg{Int}) typeintersect(Int, Vararg{Int})
19831983
@test_throws TypeError(:typeassert, Type, 1) typeintersect(1, Int)
19841984
@test_throws TypeError(:typeassert, Type, 1) typeintersect(Int, 1)
1985+
1986+
let A = Tuple{typeof(identity), Type{Union{}}},
1987+
B = Tuple{typeof(identity), typeof(Union{})}
1988+
@test A == B && (Base.isdispatchtuple(A) == Base.isdispatchtuple(B))
1989+
end

0 commit comments

Comments
 (0)