Skip to content

Commit 98b8622

Browse files
authored
Merge pull request #220 from JuliaArrays/staticrangeeachindex
StaticRange eachindex
2 parents 6e4430a + 2980f6a commit 98b8622

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterface"
22
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
3-
version = "3.1.34"
3+
version = "3.1.35"
44

55
[deps]
66
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/ranges.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ end
399399

400400
const OptionallyStaticRange = Union{<:OptionallyStaticUnitRange,<:OptionallyStaticStepRange}
401401

402-
Base.eachindex(r::OptionallyStaticRange) = r
402+
Base.eachindex(r::OptionallyStaticRange) = One():static_length(r)
403403
@inline function Base.iterate(r::OptionallyStaticRange)
404404
isempty(r) && return nothing
405405
fi = Int(first(r));

test/ranges.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,8 @@
106106
@test ArrayInterface.static_step(Base.OneTo(one(UInt))) === static(1)
107107

108108
@test Base.setindex(1:5, [6,2], 1:2) == [6,2,3,4,5]
109+
110+
@test @inferred(eachindex(static(-7):static(7))) === static(1):static(15)
111+
@test @inferred((static(-7):static(7))[first(eachindex(static(-7):static(7)))]) == -7
109112
end
110113

0 commit comments

Comments
 (0)