diff --git a/src/subtype.c b/src/subtype.c index 39211fcf55d2d..b89574c315496 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -4439,7 +4439,7 @@ static jl_value_t *insert_nondiagonal(jl_value_t *type, jl_varbinding_t *troot, newa = insert_nondiagonal(a, troot, widen2ub); newb = insert_nondiagonal(b, troot, widen2ub); if (newa != a || newb != b) - type = (jl_value_t *)jl_new_struct(jl_uniontype_type, newa, newb); + type = simple_union(newa, newb); JL_GC_POP(); } 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 if (vb.innervars != NULL) { for (size_t i = 0; i < jl_array_nrows(vb.innervars); i++) { jl_tvar_t *var = (jl_tvar_t*)jl_array_ptr_ref(vb.innervars, i); - nt = jl_type_unionall(var, nt); + if (jl_has_typevar(nt, var)) + nt = jl_type_unionall(var, nt); } } JL_GC_POP(); diff --git a/test/core.jl b/test/core.jl index df799b0abf42d..7cd4be5427eb4 100644 --- a/test/core.jl +++ b/test/core.jl @@ -8067,5 +8067,6 @@ let widen_diagonal(x::UnionAll) = Base.rewrap_unionall(Base.widen_diagonal(Base. @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 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}) end