Skip to content

Commit 2092000

Browse files
authored
fix obviously_disjoint for Union Types (#49177)
1 parent e5c2c51 commit 2092000

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/subtype.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@ static int obviously_disjoint(jl_value_t *a, jl_value_t *b, int specificity)
393393
return 1;
394394
if (jl_is_unionall(a)) a = jl_unwrap_unionall(a);
395395
if (jl_is_unionall(b)) b = jl_unwrap_unionall(b);
396+
if (jl_is_uniontype(a))
397+
return obviously_disjoint(((jl_uniontype_t *)a)->a, b, specificity) &&
398+
obviously_disjoint(((jl_uniontype_t *)a)->b, b, specificity);
399+
if (jl_is_uniontype(b))
400+
return obviously_disjoint(a, ((jl_uniontype_t *)b)->a, specificity) &&
401+
obviously_disjoint(a, ((jl_uniontype_t *)b)->b, specificity);
396402
if (jl_is_datatype(a) && jl_is_datatype(b)) {
397403
jl_datatype_t *ad = (jl_datatype_t*)a, *bd = (jl_datatype_t*)b;
398404
if (ad->name != bd->name) {

test/subtype.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,3 +2474,7 @@ let a = [TypeVar(:V, Union{}, Function) for i in 1:32]
24742474
T = foldr((v, d) -> UnionAll(v, d), b; init = foldl((i, j) -> F49127{i, j}, b))
24752475
@test S <: T
24762476
end
2477+
2478+
# requires assertions enabled (to test union-split in `obviously_disjoint`)
2479+
@test !<:(Tuple{Type{Int}, Int}, Tuple{Type{Union{Int, T}}, T} where T<:Union{Int8,Int16})
2480+
@test <:(Tuple{Type{Int}, Int}, Tuple{Type{Union{Int, T}}, T} where T<:Union{Int8,Int})

0 commit comments

Comments
 (0)