Skip to content

Commit 82eae65

Browse files
authored
Merge pull request #138 from JuliaArrays/noinfiter
Don't iterate infinitely on empty ranges
2 parents abbdc6a + 7c07fe6 commit 82eae65

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ranges.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,11 @@ end
399399
const OptionallyStaticRange = Union{<:OptionallyStaticUnitRange,<:OptionallyStaticStepRange}
400400

401401
Base.eachindex(r::OptionallyStaticRange) = r
402-
@inline Base.iterate(r::OptionallyStaticRange) = (fi = Int(first(r)); (fi, fi))
402+
@inline function Base.iterate(r::OptionallyStaticRange)
403+
isempty(r) && return nothing
404+
fi = Int(first(r));
405+
fi, fi
406+
end
403407

404408
Base.to_shape(x::OptionallyStaticRange) = length(x)
405409
Base.to_shape(x::Slice{T}) where {T<:OptionallyStaticRange} = length(x)

0 commit comments

Comments
 (0)