Skip to content

Commit d7b6ac3

Browse files
mbaumantkelman
authored andcommitted
Check bounds for indexing tuples by logical masks (#19737)
* Check bounds for indexing tuples by logical masks Also deprecate indexing tuples by non-vectors since that should increase the dimensionality of the tuple, but tuples are 1-d only structures. Fix #19719 * Don't use the AbstractVector typealias
1 parent e73c556 commit d7b6ac3

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

base/deprecated.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,10 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs),
11461146
end
11471147
end
11481148

1149+
# #19719
1150+
@deprecate getindex(t::Tuple, r::AbstractArray) getindex(t, vec(r))
1151+
@deprecate getindex(t::Tuple, b::AbstractArray{Bool}) getindex(t, vec(b))
1152+
11491153
@deprecate airy(z::Number) airyai(z)
11501154
@deprecate airyx(z::Number) airyaix(z)
11511155
@deprecate airyprime(z::Number) airyaiprime(z)

base/tuple.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ endof(t::Tuple) = length(t)
1515
size(t::Tuple, d) = d==1 ? length(t) : throw(ArgumentError("invalid tuple dimension $d"))
1616
getindex(t::Tuple, i::Int) = getfield(t, i)
1717
getindex(t::Tuple, i::Real) = getfield(t, convert(Int, i))
18-
getindex(t::Tuple, r::AbstractArray) = tuple([t[ri] for ri in r]...)
19-
getindex(t::Tuple, b::AbstractArray{Bool}) = getindex(t,find(b))
18+
getindex{T}(t::Tuple, r::AbstractArray{T,1}) = tuple([t[ri] for ri in r]...)
19+
getindex(t::Tuple, b::AbstractArray{Bool,1}) = length(b) == length(t) ? getindex(t,find(b)) : throw(BoundsError(t, b))
2020

2121
## iterating ##
2222

test/tuple.jl

+8
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,11 @@ for n = 0:20
170170
@test t[i] == i
171171
end
172172
end
173+
174+
# issue #19719
175+
@test_throws BoundsError (1,2,3)[falses(4)]
176+
@test_throws BoundsError (1,2,3)[[false,false,true,true]]
177+
@test_throws BoundsError (1,2,3)[trues(2)]
178+
@test_throws BoundsError (1,2,3)[falses(2)]
179+
@test_throws BoundsError ()[[false]]
180+
@test_throws BoundsError ()[[true]]

0 commit comments

Comments
 (0)