Skip to content

Commit 8ccf2d6

Browse files
authored
fix obvious_subtype bug with egal objects (#45771)
When egal objects contain identical typevars with different environments, the resulting subtyping might not be so obvious. Fix #45703
1 parent a549929 commit 8ccf2d6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/subtype.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,8 +1542,15 @@ static int obvious_subtype(jl_value_t *x, jl_value_t *y, jl_value_t *y0, int *su
15421542
*subtype = 1;
15431543
return 1;
15441544
}
1545-
if (jl_is_unionall(x))
1546-
x = jl_unwrap_unionall(x);
1545+
while (jl_is_unionall(x)) {
1546+
if (!jl_is_unionall(y)) {
1547+
if (obvious_subtype(jl_unwrap_unionall(x), y, y0, subtype) && !*subtype)
1548+
return 1;
1549+
return 0;
1550+
}
1551+
x = ((jl_unionall_t*)x)->body;
1552+
y = ((jl_unionall_t*)y)->body;
1553+
}
15471554
if (jl_is_unionall(y))
15481555
y = jl_unwrap_unionall(y);
15491556
if (x == (jl_value_t*)jl_typeofbottom_type->super)

test/subtype.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,3 +1987,12 @@ let A = Tuple{typeof(identity), Type{Union{}}},
19871987
B = Tuple{typeof(identity), typeof(Union{})}
19881988
@test A == B && (Base.isdispatchtuple(A) == Base.isdispatchtuple(B))
19891989
end
1990+
1991+
# issue #45703
1992+
# requires assertions enabled (to catch discrepancy in obvious_subtype)
1993+
let T = TypeVar(:T, Real),
1994+
V = TypeVar(:V, AbstractVector{T}),
1995+
S = Type{Pair{T, V}}
1996+
@test !(UnionAll(T, UnionAll(V, UnionAll(T, Type{Pair{T, V}}))) <: UnionAll(T, UnionAll(V, Type{Pair{T, V}})))
1997+
@test !(UnionAll(T, UnionAll(V, UnionAll(T, S))) <: UnionAll(T, UnionAll(V, S)))
1998+
end

0 commit comments

Comments
 (0)