Skip to content

Commit

Permalink
fix #31496, type intersection bug in restoring environment (#31669)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Apr 11, 2019
1 parent b08f120 commit 1001087
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2445,11 +2445,22 @@ static jl_value_t *intersect_all(jl_value_t *x, jl_value_t *y, jl_stenv_t *e)
e->Runions.more = 0;
memset(e->Runions.stack, 0, sizeof(e->Runions.stack));
jl_value_t **is;
JL_GC_PUSHARGS(is, 2);
JL_GC_PUSHARGS(is, 3);
jl_value_t **saved = &is[2];
jl_savedenv_t se;
save_env(e, saved, &se);
int lastset = 0, niter = 0, total_iter = 0;
jl_value_t *ii = intersect(x, y, e, 0);
if (ii == jl_bottom_type) {
restore_env(e, *saved, &se);
}
else {
free(se.buf);
save_env(e, saved, &se);
}
while (e->Runions.more) {
if (e->emptiness_only && ii != jl_bottom_type) {
free(se.buf);
JL_GC_POP();
return ii;
}
Expand All @@ -2463,6 +2474,13 @@ static jl_value_t *intersect_all(jl_value_t *x, jl_value_t *y, jl_stenv_t *e)

is[0] = ii;
is[1] = intersect(x, y, e, 0);
if (is[1] == jl_bottom_type) {
restore_env(e, *saved, &se);
}
else {
free(se.buf);
save_env(e, saved, &se);
}
if (is[0] == jl_bottom_type)
ii = is[1];
else if (is[1] == jl_bottom_type)
Expand All @@ -2474,10 +2492,12 @@ static jl_value_t *intersect_all(jl_value_t *x, jl_value_t *y, jl_stenv_t *e)
}
total_iter++;
if (niter > 3 || total_iter > 400000) {
free(se.buf);
JL_GC_POP();
return y;
}
}
free(se.buf);
JL_GC_POP();
return ii;
}
Expand Down
7 changes: 7 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1464,3 +1464,10 @@ end
@testintersect(Tuple{Type{Val{T}},Integer,T} where T>:Integer,
Tuple{Type,Int,Int},
Tuple{Type{Val{T}},Int,Int} where T>:Integer)

# issue #31496
CovType{T} = Union{AbstractArray{T,2},
Vector{UpperTriangular{T,Matrix{T}}}}
@testintersect(Pair{<:Any, <:AbstractMatrix},
Pair{T, <:CovType{T}} where T<:AbstractFloat,
Pair{T,S} where S<:AbstractArray{T,2} where T<:AbstractFloat)

0 comments on commit 1001087

Please sign in to comment.