Skip to content

Commit

Permalink
Handle integer bounds on left arguments in the environment
Browse files Browse the repository at this point in the history
In subtyping proper, variables introduced on the left (i.e. forall
variables) don't have any equality constraints, because we have no
syntax for creating them. However, intersection does sometimes create
such environments, so we need to handle it in subtyping.
  • Loading branch information
Keno committed May 17, 2019
1 parent e056490 commit a3db5f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1048,15 +1048,17 @@ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, in
env.i = env.j = 0;
env.vx = env.vy = 0;
env.vvx = env.vvy = JL_VARARG_NONE;
if (env.lx > 0)
jl_varbinding_t *xbb = NULL;
if (env.lx > 0) {
env.vvx = jl_vararg_kind(jl_tparam(env.xd, env.lx-1));
if (env.vvx == JL_VARARG_BOUND)
xbb = lookup(e, (jl_tvar_t *)jl_tparam1(jl_tparam(env.xd, env.lx - 1)));
}
if (env.ly > 0)
env.vvy = jl_vararg_kind(jl_tparam(env.yd, env.ly-1));
if (env.vvx != JL_VARARG_NONE && env.vvx != JL_VARARG_INT) {
jl_varbinding_t *bb = NULL;
if (env.vvx == JL_VARARG_BOUND)
bb = lookup(e, (jl_tvar_t*)jl_tparam1(jl_tparam(env.xd, env.lx-1)));
if (env.vvx == JL_VARARG_UNBOUND || (bb && !bb->right)) {
if (env.vvx != JL_VARARG_NONE && env.vvx != JL_VARARG_INT &&
(!xbb || !jl_is_long(xbb->lb))) {
if (env.vvx == JL_VARARG_UNBOUND || (xbb && !xbb->right)) {
// Unbounded on the LHS, bounded on the RHS
if (env.vvy == JL_VARARG_NONE || env.vvy == JL_VARARG_INT)
return 0;
Expand All @@ -1071,6 +1073,8 @@ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, in
size_t nx = env.lx;
if (env.vvx == JL_VARARG_INT)
nx += jl_vararg_length(jl_tparam(env.xd, env.lx-1)) - 1;
else if (xbb && jl_is_long(xbb->lb))
nx += jl_unbox_long(xbb->lb) - 1;
else
assert(env.vvx == JL_VARARG_NONE);
size_t ny = env.ly;
Expand Down
4 changes: 4 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1584,3 +1584,7 @@ let T31805 = Tuple{Type{Tuple{}}, Tuple{Vararg{Int8, A}}} where A,
S31805 = Tuple{Type{Tuple{Vararg{Int32, A}}}, Tuple{Vararg{Int16, A}}} where A
@test !issub(T31805, S31805)
end
@testintersect(
Tuple{Array{Tuple{Vararg{Int64,N}},N},Tuple{Vararg{Array{Int64,1},N}}} where N,
Tuple{Array{Tuple{Int64},1}, Tuple},
Tuple{Array{Tuple{Int64},1},Tuple{Array{Int64,1}}})

0 comments on commit a3db5f6

Please sign in to comment.