diff --git a/src/subtype.c b/src/subtype.c index 84868a302022a..eefcb4caf1e72 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -573,6 +573,11 @@ static int var_gt(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int param) return 0; bb->lb = simple_join(bb->lb, a); assert(bb->lb != (jl_value_t*)b); + if (jl_is_typevar(a)) { + jl_varbinding_t *aa = lookup(e, (jl_tvar_t*)a); + if (aa && !aa->right && bb->depth0 != aa->depth0 && param == 2 && var_outside(e, b, (jl_tvar_t*)a)) + return subtype_left_var(aa->ub, aa->lb, e); + } return 1; } @@ -960,7 +965,7 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param) if (xr) { if (yy) record_var_occurrence(yy, e, param); if (yr) { - if (xx) record_var_occurrence(xx, e, param); + record_var_occurrence(xx, e, param); return subtype(xx->lb, yy->ub, e, 0); } return var_lt((jl_tvar_t*)x, y, e, param); @@ -1410,6 +1415,7 @@ static int subtype_in_env(jl_value_t *x, jl_value_t *y, jl_stenv_t *e) e2.vars = e->vars; e2.intersection = e->intersection; e2.ignore_free = e->ignore_free; + e2.invdepth = e->invdepth; e2.envsz = e->envsz; e2.envout = e->envout; e2.envidx = e->envidx; @@ -1624,6 +1630,8 @@ static int subtype_in_env_existential(jl_value_t *x, jl_value_t *y, jl_stenv_t * { jl_varbinding_t *v = e->vars; int len = 0; + if (x == jl_bottom_type || y == (jl_value_t*)jl_any_type) + return 1; while (v != NULL) { len++; v = v->prev; diff --git a/test/subtype.jl b/test/subtype.jl index acd253fa035f0..76885a06bd8ed 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1529,3 +1529,16 @@ end Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L}, # TODO: this could be narrower Tuple{Type{SA{2, L}}, Type{SA{2, 16}}} where L) + +# issue #31993 +@testintersect(Tuple{Type{<:AbstractVector{T}}, Int} where T, + Tuple{Type{Vector}, Any}, + Union{}) +@testintersect(Tuple{Type{<:AbstractVector{T}}, Int} where T, + Tuple{Type{Vector{T} where Int<:T<:Int}, Any}, + Tuple{Type{Vector{Int}}, Int}) +let X = LinearAlgebra.Symmetric{T, S} where S<:(AbstractArray{U, 2} where U<:T) where T, + Y = Union{LinearAlgebra.Hermitian{T, S} where S<:(AbstractArray{U, 2} where U<:T) where T, + LinearAlgebra.Symmetric{T, S} where S<:(AbstractArray{U, 2} where U<:T) where T} + @test X <: Y +end