Skip to content

Commit

Permalink
More circulation check.
Browse files Browse the repository at this point in the history
The intersect result looks terrible.
But at least don't stack-overflow or return a `Union`.
  • Loading branch information
N5N3 committed Jan 7, 2023
1 parent dee7019 commit ea3ea0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -3215,7 +3215,9 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa
}
if (!ccheck)
return jl_bottom_type;
if (var_occurs_inside(xub, (jl_tvar_t*)y, 0, 0) && var_occurs_inside(yub, (jl_tvar_t*)x, 0, 0)) {
if ((jl_has_typevar(xub, (jl_tvar_t*)y) || jl_has_typevar(xub, (jl_tvar_t*)x)) &&
(jl_has_typevar(yub, (jl_tvar_t*)x) || jl_has_typevar(yub, (jl_tvar_t*)y))) {
// TODO: This doesn't make much sense.
// circular constraint. the result will be Bottom, but in the meantime
// we need to avoid computing intersect(xub, yub) since it won't terminate.
return y;
Expand Down
12 changes: 12 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,18 @@ struct T48006{A1,A2,A3} end
Tuple{T48006{F2, I, S2}, I} where {F2<:Real, I<:Int, S2<:Union{Int8, Val{F2}}},
Tuple{T48006{Float64, Int, S1}, Int} where S1<:Union{Val{Float64}, Int8})

# https://github.com/JuliaLang/julia/pull/31167#issuecomment-1358381818
let S = Tuple{Type{T1}, T1, Val{T1}} where T1<:(Val{S1} where S1<:Val),
T = Tuple{Union{Type{T2}, Type{S2}}, Union{Val{T2}, Val{S2}}, Union{Val{T2}, S2}} where T2<:Val{A2} where A2 where S2<:Val
I1 = typeintersect(S, T)
I2 = typeintersect(T, S)
@test I1 !== Union{} && I2 !== Union{}
@test_broken I1 <: S
@test_broken I2 <: T
@test I2 <: S
@test_broken I2 <: T
end

@testset "known subtype/intersect issue" begin
#issue 45874
# Causes a hang due to jl_critical_error calling back into malloc...
Expand Down

0 comments on commit ea3ea0e

Please sign in to comment.