Skip to content

Commit

Permalink
make sure env is restored between subtype_in_env_existential
Browse files Browse the repository at this point in the history
  • Loading branch information
N5N3 committed Dec 28, 2022
1 parent dd8d58e commit 45de1ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2361,8 +2361,12 @@ static jl_value_t *intersect_var(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int
JL_GC_PUSH2(&ub, &root);
if (!jl_has_free_typevars(a)) {
save_env(e, &root, &se);
int issub = subtype_in_env_existential(bb->lb, a, e, 0, d) && subtype_in_env_existential(a, bb->ub, e, 1, d);
int issub = subtype_in_env_existential(bb->lb, a, e, 0, d);
restore_env(e, root, &se);
if (issub) {
issub = subtype_in_env_existential(a, bb->ub, e, 1, d);
restore_env(e, root, &se);
}
free_env(&se);
if (!issub) {
JL_GC_POP();
Expand Down Expand Up @@ -2938,8 +2942,11 @@ static jl_value_t *intersect_invariant(jl_value_t *x, jl_value_t *y, jl_stenv_t
save_env(e, &root, &se);
if (!subtype_in_env_existential(x, y, e, 0, e->invdepth))
ii = NULL;
else if (!subtype_in_env_existential(y, x, e, 0, e->invdepth))
ii = NULL;
else {
restore_env(e, root, &se);
if (!subtype_in_env_existential(y, x, e, 0, e->invdepth))
ii = NULL;
}
restore_env(e, root, &se);
free_env(&se);
JL_GC_POP();
Expand Down
14 changes: 10 additions & 4 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,16 @@ T46784{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}}, M, Union{Abstr
@testintersect(T46784{T,S} where {T,S}, T46784, !Union{})
@test_broken T46784 <: T46784{T,S} where {T,S}

#issue 36185
let S = Tuple{Type{T},Array{Union{T,Missing},N}} where {T,N},
T = Tuple{Type{T},Array{Union{T,Nothing},N}} where {T,N}
@testintersect(S, T, !Union{})
I = typeintersect(S, T)
@test (Tuple{Type{Any},Array{Any,N}} where {N}) <: I
@test_broken I <: S
@test_broken I <: T
end

@testset "known subtype/intersect issue" begin
#issue 45874
# Causes a hang due to jl_critical_error calling back into malloc...
Expand Down Expand Up @@ -2313,10 +2323,6 @@ T46784{B<:Val, M<:AbstractMatrix} = Tuple{<:Union{B, <:Val{<:B}}, M, Union{Abstr
B = Tuple{NTuple{N, Int}, NTuple{N, Int}, NTuple{N, Int}} where N
@test_broken !(A <: B)

#issue 36185
@test_broken typeintersect((Tuple{Type{T},Array{Union{T,Missing},N}} where {T,N}),
(Tuple{Type{T},Array{Union{T,Nothing},N}} where {T,N})) <: Any

#issue 35698
@test_broken typeintersect(Type{Tuple{Array{T,1} where T}}, UnionAll) != Union{}

Expand Down

0 comments on commit 45de1ce

Please sign in to comment.