Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #45703, assertion failure in subtyping #45771

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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