From c346cbe53bc9eb184f59b00daad496b6de6e58a6 Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Tue, 16 Jan 2024 21:04:54 +0800 Subject: [PATCH] Fix `widen_diagonal` bug for nested unionall --- src/subtype.c | 9 ++++----- test/core.jl | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/subtype.c b/src/subtype.c index 17a6bf7041e3bc..50b62c9b6e3da0 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -4460,19 +4460,18 @@ static jl_value_t *insert_nondiagonal(jl_value_t *type, jl_varbinding_t *troot, jl_value_t *newbody = insert_nondiagonal(body, troot, widen2ub); if (v) v->var = var; // And restore it after inner insertation. jl_value_t *newvar = NULL; - JL_GC_PUSH2(&newbody, &newvar); + JL_GC_PUSH3(&newbody, &newvar, &type); if (body == newbody || jl_has_typevar(newbody, var)) { if (body != newbody) - newbody = jl_new_struct(jl_unionall_type, var, newbody); + type = jl_new_struct(jl_unionall_type, var, newbody); // n.b. we do not widen lb, since that would be the wrong direction newvar = insert_nondiagonal(var->ub, troot, widen2ub); if (newvar != var->ub) { newvar = (jl_value_t*)jl_new_typevar(var->name, var->lb, newvar); - newbody = jl_apply_type1(newbody, newvar); - newbody = jl_type_unionall((jl_tvar_t*)newvar, newbody); + newbody = jl_apply_type1(type, newvar); + type = jl_type_unionall((jl_tvar_t*)newvar, newbody); } } - type = newbody; JL_GC_POP(); } else if (jl_is_uniontype(type)) { diff --git a/test/core.jl b/test/core.jl index 1f66d72c40c5e7..96968f9052d75e 100644 --- a/test/core.jl +++ b/test/core.jl @@ -8077,13 +8077,13 @@ end # Test correctness of widen_diagonal let widen_diagonal(x::UnionAll) = Base.rewrap_unionall(Base.widen_diagonal(Base.unwrap_unionall(x), x), x), - check_widen_diagonal(x, y) = !<:(x, y) && x <: widen_diagonal(y) @test Tuple{Int,Float64} <: widen_diagonal(NTuple) @test Tuple{Int,Float64} <: widen_diagonal(Tuple{T,T} where {T}) @test Tuple{Real,Int,Float64} <: widen_diagonal(Tuple{S,Vararg{T}} where {S, T<:S}) @test Tuple{Int,Int,Float64,Float64} <: widen_diagonal(Tuple{S,S,Vararg{T}} where {S, T<:S}) @test Union{Tuple{T}, Tuple{T,Int}} where {T} === widen_diagonal(Union{Tuple{T}, Tuple{T,Int}} where {T}) @test Tuple === widen_diagonal(Union{Tuple{Vararg{S}}, Tuple{Vararg{T}}} where {S, T}) + @test Tuple{Vararg{Val{<:Set}}} == widen_diagonal(Tuple{Vararg{T}} where T<:Val{<:Set}) end # Test try/catch/else ordering