From bdc07ed0ec2afde3ea0e22b7f8d0fa8073e7a0bc Mon Sep 17 00:00:00 2001 From: Andy Ferris Date: Thu, 11 Jun 2020 15:22:57 +1000 Subject: [PATCH] Forbid IteratorSize of HasShape for Indices Fixes #20 --- src/AbstractIndices.jl | 2 +- src/Indices.jl | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/AbstractIndices.jl b/src/AbstractIndices.jl index 08db8e6..27f5236 100644 --- a/src/AbstractIndices.jl +++ b/src/AbstractIndices.jl @@ -63,7 +63,7 @@ function Base.in(i, indices::AbstractIndices{I}) where I end # Match the default setting from Base - the majority of containers will know their size -Base.IteratorSize(indices::AbstractIndices) = Base.HasLength() +Base.IteratorSize(::AbstractIndices) = Base.HasLength() function Base.length(indices::AbstractIndices) if Base.IteratorSize(indices) isa Base.SizeUnknown diff --git a/src/Indices.jl b/src/Indices.jl index 6ae91ae..0025b5f 100644 --- a/src/Indices.jl +++ b/src/Indices.jl @@ -26,7 +26,13 @@ Indices{I}(iter) where {I} = Indices{I, typeof(iter)}(iter) # There is a corner end Base.in(i::I, inds::Indices{I}) where {I} = in(i, inds.inds) -Base.IteratorSize(i::Indices) = Base.IteratorSize(i.inds) +function Base.IteratorSize(i::Indices) + out = Base.IteratorSize(i.inds) + if out isa Base.HasShape + return Base.HasLength() + end + return out +end Base.length(i::Indices) = length(i.inds) # Specialize for `Vector` elements. Satisfy the tokenization and insertion interface