From cf5a16e21f53be1eb68255ccd0fa600f66feeb62 Mon Sep 17 00:00:00 2001 From: Justin Willmert Date: Tue, 31 Dec 2019 14:21:07 -0600 Subject: [PATCH] Add CartesianIndices(()) for Ref getindex and setindex! --- base/multidimensional.jl | 2 ++ test/abstractarray.jl | 3 +++ 2 files changed, 5 insertions(+) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 3745186f5cc4f4..7da3fd5f7cbdbb 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1802,4 +1802,6 @@ function _sortslices(A::AbstractArray, d::Val{dims}; kws...) where dims end getindex(b::Ref, ::CartesianIndex{0}) = getindex(b) +getindex(b::Ref, ::CartesianIndices{0,Tuple{}}) = getindex(b) setindex!(b::Ref, x, ::CartesianIndex{0}) = setindex!(b, x) +setindex!(b::Ref, x, ::CartesianIndices{0,Tuple{}}) = setindex!(b, x) diff --git a/test/abstractarray.jl b/test/abstractarray.jl index 8d0c2617d78f09..72af4b889ccabb 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -991,8 +991,11 @@ end @testset "getindex and setindex! for Ref" begin for x in [Ref(1), Ref([1,2,3], 1)] @test getindex(x) == getindex(x, CartesianIndex()) == 1 + @test getindex(x) == getindex(x, CartesianIndices(())) == 1 x[CartesianIndex()] = 10 @test getindex(x) == getindex(x, CartesianIndex()) == 10 + x[CartesianIndices(())] = 11 + @test getindex(x) == getindex(x, CartesianIndices(())) == 11 end end