Skip to content

Commit b9fdc9c

Browse files
committed
fuse simple_union for Union normalization
add add check before innervar wrapping.
1 parent 328b554 commit b9fdc9c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/subtype.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4439,7 +4439,7 @@ static jl_value_t *insert_nondiagonal(jl_value_t *type, jl_varbinding_t *troot,
44394439
newa = insert_nondiagonal(a, troot, widen2ub);
44404440
newb = insert_nondiagonal(b, troot, widen2ub);
44414441
if (newa != a || newb != b)
4442-
type = (jl_value_t *)jl_new_struct(jl_uniontype_type, newa, newb);
4442+
type = simple_union(newa, newb);
44434443
JL_GC_POP();
44444444
}
44454445
else if (jl_is_vararg(type)) {
@@ -4499,7 +4499,8 @@ static jl_value_t *widen_diagonal(jl_value_t *t, jl_unionall_t *u, jl_varbinding
44994499
if (vb.innervars != NULL) {
45004500
for (size_t i = 0; i < jl_array_nrows(vb.innervars); i++) {
45014501
jl_tvar_t *var = (jl_tvar_t*)jl_array_ptr_ref(vb.innervars, i);
4502-
nt = jl_type_unionall(var, nt);
4502+
if (jl_has_typevar(nt, var))
4503+
nt = jl_type_unionall(var, nt);
45034504
}
45044505
}
45054506
JL_GC_POP();

test/core.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8067,5 +8067,6 @@ let widen_diagonal(x::UnionAll) = Base.rewrap_unionall(Base.widen_diagonal(Base.
80678067
@test Tuple{Int,Float64} <: widen_diagonal(Tuple{T,T} where {T})
80688068
@test Tuple{Real,Int,Float64} <: widen_diagonal(Tuple{S,Vararg{T}} where {S, T<:S})
80698069
@test Tuple{Int,Int,Float64,Float64} <: widen_diagonal(Tuple{S,S,Vararg{T}} where {S, T<:S})
8070-
@test Union{Tuple{T}, Tuple{T,Int}} where {T} == widen_diagonal(Union{Tuple{T}, Tuple{T,Int}} where {T})
8070+
@test Union{Tuple{T}, Tuple{T,Int}} where {T} === widen_diagonal(Union{Tuple{T}, Tuple{T,Int}} where {T})
8071+
@test Tuple === widen_diagonal(Union{Tuple{Vararg{S}}, Tuple{Vararg{T}}} where {S, T})
80718072
end

0 commit comments

Comments
 (0)