Skip to content

Commit a37dd16

Browse files
authored
Make isdispatchtuple consistent for typeof(Union{}) (JuliaLang#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 JuliaLang#45347
1 parent 390503e commit a37dd16

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/jltypes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ void jl_precompute_memoized_dt(jl_datatype_t *dt, int cacheable)
12151215
if (dt->isdispatchtuple) {
12161216
dt->isdispatchtuple = jl_is_datatype(p) &&
12171217
((!jl_is_kind(p) && ((jl_datatype_t*)p)->isconcretetype) ||
1218+
(p == (jl_value_t*)jl_typeofbottom_type) || // == Type{Union{}}, so needs to be consistent
12181219
(((jl_datatype_t*)p)->name == jl_type_typename && !((jl_datatype_t*)p)->hasfreetypevars));
12191220
}
12201221
if (istuple && dt->has_concrete_subtype) {

test/subtype.jl

Lines changed: 5 additions & 0 deletions
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)