Skip to content

Commit

Permalink
fix obvious_subtype bug with egal objects (#45771)
Browse files Browse the repository at this point in the history
When egal objects contain identical typevars with different
environments, the resulting subtyping might not be so obvious.

Fix #45703

(cherry picked from commit 8ccf2d6)
  • Loading branch information
JeffBezanson authored and KristofferC committed Jul 4, 2022
1 parent d53bd6f commit f6e0600
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1542,8 +1542,15 @@ static int obvious_subtype(jl_value_t *x, jl_value_t *y, jl_value_t *y0, int *su
*subtype = 1;
return 1;
}
if (jl_is_unionall(x))
x = jl_unwrap_unionall(x);
while (jl_is_unionall(x)) {
if (!jl_is_unionall(y)) {
if (obvious_subtype(jl_unwrap_unionall(x), y, y0, subtype) && !*subtype)
return 1;
return 0;
}
x = ((jl_unionall_t*)x)->body;
y = ((jl_unionall_t*)y)->body;
}
if (jl_is_unionall(y))
y = jl_unwrap_unionall(y);
if (x == (jl_value_t*)jl_typeofbottom_type->super)
Expand Down
9 changes: 9 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1987,3 +1987,12 @@ let A = Tuple{typeof(identity), Type{Union{}}},
B = Tuple{typeof(identity), typeof(Union{})}
@test A == B && (Base.isdispatchtuple(A) == Base.isdispatchtuple(B))
end

# issue #45703
# requires assertions enabled (to catch discrepancy in obvious_subtype)
let T = TypeVar(:T, Real),
V = TypeVar(:V, AbstractVector{T}),
S = Type{Pair{T, V}}
@test !(UnionAll(T, UnionAll(V, UnionAll(T, Type{Pair{T, V}}))) <: UnionAll(T, UnionAll(V, Type{Pair{T, V}})))
@test !(UnionAll(T, UnionAll(V, UnionAll(T, S))) <: UnionAll(T, UnionAll(V, S)))
end

0 comments on commit f6e0600

Please sign in to comment.