Skip to content

Commit 792229a

Browse files
authored
Fix ambiguity in indexing with zero-dimensional sub arrays (#15)
1 parent 0e567f7 commit 792229a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/cardinality.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ getindex(A::Array, i1::InfiniteCardinal{0}, I::Integer...) = throw(BoundsError(A
204204
Base._unsafe_getindex(::IndexStyle, A::AbstractArray, I::InfiniteCardinal{0}) = error("Overload getindex(::$(typeof(A)), ::InfiniteCardinal{0})")
205205

206206
# Avoid too-strict restrictions in SubArray
207-
function getindex(V::SubArray{T,N}, I::Vararg{InfiniteCardinal{0},N}) where {T,N}
208-
@boundscheck checkbounds(V, I...)
209-
@inbounds r = V.parent[Base.reindex(V.indices, I)...]
207+
function getindex(V::SubArray{T,N}, i1::InfiniteCardinal{0}, I::Integer...) where {T,N}
208+
@boundscheck checkbounds(V, i1, I...)
209+
@inbounds r = V.parent[Base.reindex(V.indices, tuple(i1, I...))...]
210210
r
211211
end

test/test_cardinality.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,7 @@ using Infinities, Base64, Base.Checked, Test
133133
@test_throws BoundsError randn(3)[ℵ₀]
134134
@test_throws ErrorException Base._unsafe_getindex(IndexCartesian(),permutedims(1:3)',ℵ₀)
135135
@test_throws BoundsError view(randn(3),1:2)[ℵ₀]
136+
# check ambiguity is not introduced
137+
@test view(collect(1:5),2)[] == 2
136138
end
137139
end

0 commit comments

Comments
 (0)