Skip to content

Commit e0bb770

Browse files
committed
Fixed views of zero-dimensional arrays
1 parent a00c446 commit e0bb770

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/indexing.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,8 @@ Base.unsafe_view(A::AbstractArray, i1::StaticIndexing, indices::StaticIndexing..
379379
# instead of unsafe_view so we need this method too (Base._maybe_reindex
380380
# is a good example)
381381
Base.SubArray(A::AbstractArray, indices::NTuple{<:Any,StaticIndexing}) = Base.SubArray(A, map(unwrap, indices))
382+
# this method is defined to prevent infinite recursion when viewing a
383+
# zero-dimensional array (see issue #705)
384+
function Base.SubArray(A::AbstractArray, indices::Tuple{})
385+
return invoke(Base.SubArray, Tuple{AbstractArray, Tuple}, A, indices)
386+
end

test/indexing.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ using StaticArrays, Test
205205
@test (zeros(2,0)[SVector(1),SVector{0,Int}()] = 0) == 0
206206
end
207207

208+
@testset "Viewing zero-dimensional arrays" begin
209+
# issue #705
210+
A = zeros()
211+
B = MArray{Tuple{},Float64,0,1}(0.0)
212+
@test @inferred(view(A))[] == 0.0
213+
@test @inferred(view(B))[] == 0.0
214+
end
215+
208216
@testset "Using SArray as index for view" begin
209217
a = collect(11:20)
210218
@test view(a, SVector(1,2,3)) == [11,12,13]

0 commit comments

Comments
 (0)