Skip to content

Commit

Permalink
fix #31993, intersection of Type{Vec} and Type{<:Vec{T}}
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 10, 2019
1 parent 6f463da commit 1b418fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1b418fd

Please sign in to comment.