Skip to content

Commit

Permalink
avoid forming circular lower bound in type intersection (JuliaLang#38114
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Oct 23, 2020
1 parent bd9abdc commit 1994981
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2931,7 +2931,10 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa
jl_value_t *ub=NULL, *lb=NULL;
JL_GC_PUSH2(&lb, &ub);
ub = intersect_aside(xub, yub, e, 0, xx ? xx->depth0 : 0);
lb = simple_join(xlb, ylb);
if (xlb == y)
lb = ylb;
else
lb = simple_join(xlb, ylb);
if (yy) {
if (lb != y)
yy->lb = lb;
Expand Down
14 changes: 14 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1772,3 +1772,17 @@ end

# issue #37255
@test Type{Union{}} == Type{T} where {Union{}<:T<:Union{}}

# issue #38081
struct AlmostLU{T, S<:AbstractMatrix{T}}
end
let X1 = Tuple{AlmostLU, Vector{T}} where T,
X2 = Tuple{AlmostLU{S, X} where X<:Matrix, Vector{S}} where S<:Union{Float32, Float64},
I = typeintersect(X1, X2)
# TODO: the quality of this intersection is not great; for now just test that it
# doesn't stack overflow
@test I<:X1 || I<:X2
actual = Tuple{AlmostLU{S, X} where X<:Matrix{S}, Vector{S}} where S<:Union{Float32, Float64}
@test I >: actual
@test_broken I == actual
end

0 comments on commit 1994981

Please sign in to comment.