Skip to content

Commit

Permalink
Make isdispatchtuple consistent for typeof(Union{}) (#45348)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Keno authored May 22, 2022
1 parent 390503e commit a37dd16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ void jl_precompute_memoized_dt(jl_datatype_t *dt, int cacheable)
if (dt->isdispatchtuple) {
dt->isdispatchtuple = jl_is_datatype(p) &&
((!jl_is_kind(p) && ((jl_datatype_t*)p)->isconcretetype) ||
(p == (jl_value_t*)jl_typeofbottom_type) || // == Type{Union{}}, so needs to be consistent
(((jl_datatype_t*)p)->name == jl_type_typename && !((jl_datatype_t*)p)->hasfreetypevars));
}
if (istuple && dt->has_concrete_subtype) {
Expand Down
5 changes: 5 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1982,3 +1982,8 @@ end
@test_throws TypeError(:typeassert, Type, Vararg{Int}) typeintersect(Int, Vararg{Int})
@test_throws TypeError(:typeassert, Type, 1) typeintersect(1, Int)
@test_throws TypeError(:typeassert, Type, 1) typeintersect(Int, 1)

let A = Tuple{typeof(identity), Type{Union{}}},
B = Tuple{typeof(identity), typeof(Union{})}
@test A == B && (Base.isdispatchtuple(A) == Base.isdispatchtuple(B))
end

0 comments on commit a37dd16

Please sign in to comment.