Skip to content

Commit 47999ab

Browse files
committed
Fix widen_diagonal bug for nested UnionAll (#52924)
1 parent f9c2461 commit 47999ab

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/subtype.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4415,19 +4415,18 @@ static jl_value_t *insert_nondiagonal(jl_value_t *type, jl_varbinding_t *troot,
44154415
jl_value_t *newbody = insert_nondiagonal(body, troot, widen2ub);
44164416
if (v) v->var = var; // And restore it after inner insertation.
44174417
jl_value_t *newvar = NULL;
4418-
JL_GC_PUSH2(&newbody, &newvar);
4418+
JL_GC_PUSH3(&newbody, &newvar, &type);
44194419
if (body == newbody || jl_has_typevar(newbody, var)) {
44204420
if (body != newbody)
4421-
newbody = jl_new_struct(jl_unionall_type, var, newbody);
4421+
type = jl_new_struct(jl_unionall_type, var, newbody);
44224422
// n.b. we do not widen lb, since that would be the wrong direction
44234423
newvar = insert_nondiagonal(var->ub, troot, widen2ub);
44244424
if (newvar != var->ub) {
44254425
newvar = (jl_value_t*)jl_new_typevar(var->name, var->lb, newvar);
4426-
newbody = jl_apply_type1(newbody, newvar);
4427-
newbody = jl_type_unionall((jl_tvar_t*)newvar, newbody);
4426+
newbody = jl_apply_type1(type, newvar);
4427+
type = jl_type_unionall((jl_tvar_t*)newvar, newbody);
44284428
}
44294429
}
4430-
type = newbody;
44314430
JL_GC_POP();
44324431
}
44334432
else if (jl_is_uniontype(type)) {

test/core.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8074,12 +8074,12 @@ end
80748074
@test Core.Compiler.is_foldable(Base.infer_effects(getindex, (Core.SimpleVector,Int)))
80758075

80768076
# Test correctness of widen_diagonal
8077-
let widen_diagonal(x::UnionAll) = Base.rewrap_unionall(Base.widen_diagonal(Base.unwrap_unionall(x), x), x),
8078-
check_widen_diagonal(x, y) = !<:(x, y) && x <: widen_diagonal(y)
8077+
let widen_diagonal(x::UnionAll) = Base.rewrap_unionall(Base.widen_diagonal(Base.unwrap_unionall(x), x), x)
80798078
@test Tuple{Int,Float64} <: widen_diagonal(NTuple)
80808079
@test Tuple{Int,Float64} <: widen_diagonal(Tuple{T,T} where {T})
80818080
@test Tuple{Real,Int,Float64} <: widen_diagonal(Tuple{S,Vararg{T}} where {S, T<:S})
80828081
@test Tuple{Int,Int,Float64,Float64} <: widen_diagonal(Tuple{S,S,Vararg{T}} where {S, T<:S})
80838082
@test Union{Tuple{T}, Tuple{T,Int}} where {T} === widen_diagonal(Union{Tuple{T}, Tuple{T,Int}} where {T})
80848083
@test Tuple === widen_diagonal(Union{Tuple{Vararg{S}}, Tuple{Vararg{T}}} where {S, T})
8084+
@test Tuple{Vararg{Val{<:Set}}} == widen_diagonal(Tuple{Vararg{T}} where T<:Val{<:Set})
80858085
end

0 commit comments

Comments
 (0)