From 2901f0e353c5e5fdb341caa9abce92b042248627 Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Thu, 29 Dec 2022 06:04:09 +0800 Subject: [PATCH] Avoid stack-overflow in #46736 When we perform re-`intersection_unionall`, the `Union` bounds might be generated from `simple_join and thus not identical to the src `Union`. This commit adds a fast-path to skip the following `intersect_all. --- src/subtype.c | 3 +++ test/subtype.jl | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/subtype.c b/src/subtype.c index 9356f0d943e9b..c4207840ae519 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -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; diff --git a/test/subtype.jl b/test/subtype.jl index 9239c66decff1..d5f07f722f5ca 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -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...