Skip to content

Commit

Permalink
avoid stack-overflow in JuliaLang#46736
Browse files Browse the repository at this point in the history
When we perform re-intersection_unionall, the `Union` bounds might be generated from `simple_join` thus not identical to the src `Union`.
  • Loading branch information
N5N3 committed Dec 28, 2022
1 parent 45de1ce commit 2b2b075
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,9 @@ static jl_value_t *intersect_aside(jl_value_t *x, jl_value_t *y, jl_stenv_t *e,
return y;
if (y == (jl_value_t*)jl_any_type && !jl_is_typevar(x))
return x;
// band-aid for #46736
if (jl_egal(x, y))
return x;

jl_saved_unionstate_t oldRunions; push_unionstate(&oldRunions, &e->Runions);
int savedepth = e->invdepth, Rsavedepth = e->Rinvdepth;
Expand Down
8 changes: 8 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,14 @@ let S = Tuple{Type{T},Array{Union{T,Missing},N}} where {T,N},
@test_broken I <: T
end

#issue 46736
let S = Tuple{Val{T}, T} where {S1,T<:Val{Union{Nothing,S1}}},
T = Tuple{Val{Val{Union{Nothing, S2}}}, Any} where S2
@testintersect(S, T, !Union{})
# not ideal (`S1` should be unbounded)
@test_broken testintersect(S, T) == Tuple{Val{Val{Union{Nothing, S1}}}, Val{Union{Nothing, S1}}} where S1<:(Union{Nothing, S2} where S2)
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 2b2b075

Please sign in to comment.