From 9212ca6a9a1a1656e5ad88a1d0852aa53002ad6a Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Sun, 5 Feb 2017 22:54:10 -0800 Subject: [PATCH] Remove general multidimensional indexing of tuples Previously a method for tuples existed which permited multidimensional indexing. However, the method merely splatted the dimensions and ended up calling itself, infinitely recursing. This commit replaces the method with one that permits the desired behavior for broadcast without permitting things like (1,)[1,1]. --- base/multidimensional.jl | 2 +- test/tuple.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index b7b305dd621db..20f1b04c4a138 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -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 diff --git a/test/tuple.jl b/test/tuple.jl index 4470ac6992257..acf40f4306fd5 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -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