Skip to content

Commit 1b418fd

Browse files
committed
fix #31993, intersection of Type{Vec} and Type{<:Vec{T}}
1 parent 6f463da commit 1b418fd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/subtype.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ static int var_gt(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int param)
573573
return 0;
574574
bb->lb = simple_join(bb->lb, a);
575575
assert(bb->lb != (jl_value_t*)b);
576+
if (jl_is_typevar(a)) {
577+
jl_varbinding_t *aa = lookup(e, (jl_tvar_t*)a);
578+
if (aa && !aa->right && bb->depth0 != aa->depth0 && param == 2 && var_outside(e, b, (jl_tvar_t*)a))
579+
return subtype_left_var(aa->ub, aa->lb, e);
580+
}
576581
return 1;
577582
}
578583

@@ -960,7 +965,7 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
960965
if (xr) {
961966
if (yy) record_var_occurrence(yy, e, param);
962967
if (yr) {
963-
if (xx) record_var_occurrence(xx, e, param);
968+
record_var_occurrence(xx, e, param);
964969
return subtype(xx->lb, yy->ub, e, 0);
965970
}
966971
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)
14101415
e2.vars = e->vars;
14111416
e2.intersection = e->intersection;
14121417
e2.ignore_free = e->ignore_free;
1418+
e2.invdepth = e->invdepth;
14131419
e2.envsz = e->envsz;
14141420
e2.envout = e->envout;
14151421
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 *
16241630
{
16251631
jl_varbinding_t *v = e->vars;
16261632
int len = 0;
1633+
if (x == jl_bottom_type || y == (jl_value_t*)jl_any_type)
1634+
return 1;
16271635
while (v != NULL) {
16281636
len++;
16291637
v = v->prev;

test/subtype.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,3 +1529,16 @@ end
15291529
Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L},
15301530
# TODO: this could be narrower
15311531
Tuple{Type{SA{2, L}}, Type{SA{2, 16}}} where L)
1532+
1533+
# issue #31993
1534+
@testintersect(Tuple{Type{<:AbstractVector{T}}, Int} where T,
1535+
Tuple{Type{Vector}, Any},
1536+
Union{})
1537+
@testintersect(Tuple{Type{<:AbstractVector{T}}, Int} where T,
1538+
Tuple{Type{Vector{T} where Int<:T<:Int}, Any},
1539+
Tuple{Type{Vector{Int}}, Int})
1540+
let X = LinearAlgebra.Symmetric{T, S} where S<:(AbstractArray{U, 2} where U<:T) where T,
1541+
Y = Union{LinearAlgebra.Hermitian{T, S} where S<:(AbstractArray{U, 2} where U<:T) where T,
1542+
LinearAlgebra.Symmetric{T, S} where S<:(AbstractArray{U, 2} where U<:T) where T}
1543+
@test X <: Y
1544+
end

0 commit comments

Comments
 (0)