Skip to content

Commit

Permalink
fix #27632, bug in subtyping length-constrained varargs
Browse files Browse the repository at this point in the history
Ref #27646
(cherry picked from commit 8e3120c)
  • Loading branch information
JeffBezanson authored and ararslan committed Jun 19, 2018
1 parent 161216a commit 0ae20fc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,21 @@ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, in
break; // if y ends in `Vararg{Any}` skip checking everything
}
if (vx && vy) {
jl_tvar_t *yp1=NULL, *yp2=NULL;
jl_value_t *yva = unwrap_2_unionall(yi, &yp1, &yp2);
jl_tvar_t *xp1=NULL, *xp2=NULL;
jl_value_t *xva = unwrap_2_unionall(xi, &xp1, &xp2);
if ((jl_value_t*)xp1 == jl_tparam1(xva) || (jl_value_t*)xp2 == jl_tparam1(xva)) {
// check for unconstrained vararg on left, constrained on right
if (jl_is_long(jl_tparam1(yva)))
return 0;
if (jl_is_typevar(jl_tparam1(yva))) {
jl_varbinding_t *ylv = lookup(e, (jl_tvar_t*)jl_tparam1(yva));
if (ylv && jl_is_long(ylv->lb))
return 0;
}
}

// skip testing element type if vararg lengths are 0
if (jl_is_datatype(xi)) {
jl_value_t *xl = jl_tparam1(xi);
Expand Down
10 changes: 10 additions & 0 deletions test/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,13 @@ let
su = view(u, :, 1)
@test size(@inferred(xcorr(x, su))) == (19,)
end

# issue #27632
function _test_27632(A)
for J in CartesianIndices(size(A)[2:end])
A[1, J]
end
nothing
end
# check that this doesn't crash
_test_27632(view(ones(Int64, (1, 1, 1)), 1, 1, 1))
7 changes: 7 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1179,3 +1179,10 @@ for it = 1:5
end

@test round.(x_24305, 2) == [1.78, 1.42, 1.24]

# issue #27632
@test !(Tuple{Array{Int,0}, Int, Vararg{Int}} <: Tuple{AbstractArray{T,N}, Vararg{Int,N}} where {T, N})
@test !(Tuple{Array{Int,0}, Int, Vararg{Int}} <: Tuple{AbstractArray{T,N}, Vararg{Any,N}} where {T, N})
@test !(Tuple{Array{Int,0}, Vararg{Any}} <: Tuple{AbstractArray{T,N}, Vararg{Any,N}} where {T, N})
@test Tuple{Array{Int,0},} <: Tuple{AbstractArray{T,N}, Vararg{Any,N}} where {T, N}
@test !(Tuple{Array{Int,0}, Any} <: Tuple{AbstractArray{T,N}, Vararg{Any,N}} where {T, N})

0 comments on commit 0ae20fc

Please sign in to comment.