Skip to content

Commit

Permalink
Merge pull request #20468 from JuliaLang/aa/tuple-indexing
Browse files Browse the repository at this point in the history
Remove multidimensional indexing of tuples
  • Loading branch information
pabloferz authored Feb 7, 2017
2 parents a6600d1 + 9212ca6 commit 0900553
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ uncolon(inds::Tuple, I::Tuple{Colon, Vararg{CI0}}) = Slice(OneTo(trailingsi

### From abstractarray.jl: Internal multidimensional indexing definitions ###
getindex(x::Number, i::CartesianIndex{0}) = x
getindex(t::Tuple, I...) = getindex(t, IteratorsMD.flatten(I)...)
getindex(t::Tuple, i::CartesianIndex{1}) = getindex(t, i.I[1])

# These are not defined on directly on getindex to avoid
# ambiguities for AbstractArray subtypes. See the note in abstractarray.jl
Expand Down
5 changes: 5 additions & 0 deletions test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,8 @@ end
@test Tuple{Int,Vararg{Any}}(Float64[1,2,3]) === (1, 2.0, 3.0)
@test Tuple(ones(5)) === (1.0,1.0,1.0,1.0,1.0)
@test_throws MethodError convert(Tuple, ones(5))

@testset "Multidimensional indexing (issue #20453)" begin
@test_throws MethodError (1,)[]
@test_throws MethodError (1,1,1)[1,1]
end

0 comments on commit 0900553

Please sign in to comment.