diff --git a/src/subtype.c b/src/subtype.c index 0646f6395a43c..1d169f062ef34 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -1187,7 +1187,7 @@ static jl_value_t *finish_unionall(jl_value_t *res, jl_varbinding_t *vb, jl_sten // remove/replace/rewrap free occurrences of this var in the environment jl_varbinding_t *btemp = e->vars; while (btemp != NULL) { - if (jl_has_typevar(btemp->lb, vb->var)) { + if (jl_has_typevar(btemp->lb, vb->var) && vb->lb != (jl_value_t*)btemp->var) { if (varval) btemp->lb = jl_substitute_var(btemp->lb, vb->var, varval); else if (btemp->lb == (jl_value_t*)vb->var) @@ -1196,7 +1196,7 @@ static jl_value_t *finish_unionall(jl_value_t *res, jl_varbinding_t *vb, jl_sten btemp->lb = jl_new_struct(jl_unionall_type, vb->var, btemp->lb); assert((jl_value_t*)btemp->var != btemp->lb); } - if (jl_has_typevar(btemp->ub, vb->var)) { + if (jl_has_typevar(btemp->ub, vb->var) && vb->ub != (jl_value_t*)btemp->var) { if (varval) btemp->ub = jl_substitute_var(btemp->ub, vb->var, varval); else if (btemp->ub == (jl_value_t*)vb->var) diff --git a/test/subtype.jl b/test/subtype.jl index 4ac5347df88d6..502e4130b6a4a 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -807,6 +807,11 @@ function test_intersection() Union{Tuple{S,Array{Int64,1}},Tuple{S,Array{S,1}}} where S), Union{Tuple{Vector{Int64},Vector{Int64}}, Tuple{Vector{T},Vector{T}} where T>:Vector}) + + # part of issue #20344 + @testintersect(Tuple{Type{Tuple{Vararg{T, N} where N}}, Tuple} where T, + Tuple{Type{Tuple{Vararg{T, N}}} where N where T, Any}, + Tuple{Type{Tuple{}}, Tuple}) end function test_intersection_properties()