Skip to content

Commit

Permalink
Merge pull request #229 from N5N3/1stindex
Browse files Browse the repository at this point in the history
fix for `firstindex(128:static(-1):1)`
  • Loading branch information
chriselrod authored Dec 22, 2021
2 parents fedb318 + 9126b0f commit ec8d2c7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ known_step(::Type{<:OptionallyStaticStepRange{<:Any,StaticInt{S}}}) where {S} =
known_last(::Type{<:OptionallyStaticUnitRange{<:Any,StaticInt{L}}}) where {L} = L::Int
known_last(::Type{<:OptionallyStaticStepRange{<:Any,<:Any,StaticInt{L}}}) where {L} = L::Int

Base.firstindex(x::OptionallyStaticRange) = first(x)
@inline function Base.first(r::OptionallyStaticRange)::Int
if known_first(r) === nothing
return getfield(r, :start)
Expand Down
2 changes: 2 additions & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,7 @@

@test @inferred(eachindex(static(-7):static(7))) === static(1):static(15)
@test @inferred((static(-7):static(7))[first(eachindex(static(-7):static(7)))]) == -7

@test @inferred(firstindex(128:static(-1):1)) == 1
end

0 comments on commit ec8d2c7

Please sign in to comment.