Skip to content

Commit 78b1e56

Browse files
Merge pull request #59 from Tokazama/master
Range traits now work on instance and types
2 parents 6215ede + 157e4c6 commit 78b1e56

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/ArrayInterface.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,10 @@ Otherwise, return `nothing`.
500500
@test isnothing(known_first(typeof(1:4)))
501501
@test isone(known_first(typeof(Base.OneTo(4))))
502502
"""
503-
known_first(::Any) = nothing
503+
known_first(x) = known_first(typeof(x))
504+
known_first(::Type{T}) where {T} = nothing
504505
known_first(::Type{Base.OneTo{T}}) where {T} = one(T)
506+
505507
"""
506508
known_last(::Type{T})
507509
@@ -512,7 +514,9 @@ Otherwise, return `nothing`.
512514
using StaticArrays
513515
@test known_last(typeof(SOneTo(4))) == 4
514516
"""
515-
known_last(::Any) = nothing
517+
known_last(x) = known_last(typeof(x))
518+
known_last(::Type{T}) where {T} = nothing
519+
516520
"""
517521
known_step(::Type{T})
518522
@@ -522,7 +526,8 @@ Otherwise, return `nothing`.
522526
@test isnothing(known_step(typeof(1:0.2:4)))
523527
@test isone(known_step(typeof(1:4)))
524528
"""
525-
known_step(::Any) = nothing
529+
known_step(x) = known_step(typeof(x))
530+
known_step(::Type{T}) where {T} = nothing
526531
known_step(::Type{<:AbstractUnitRange{T}}) where {T} = one(T)
527532

528533
function __init__()

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,14 @@ end
177177

178178
@testset "Range Interface" begin
179179
@test isnothing(ArrayInterface.known_first(typeof(1:4)))
180+
@test isone(ArrayInterface.known_first(Base.OneTo(4)))
180181
@test isone(ArrayInterface.known_first(typeof(Base.OneTo(4))))
181-
182+
183+
@test isnothing(ArrayInterface.known_last(1:4))
182184
@test isnothing(ArrayInterface.known_last(typeof(1:4)))
183185

184186
@test isnothing(ArrayInterface.known_step(typeof(1:0.2:4)))
187+
@test isone(ArrayInterface.known_step(1:4))
185188
@test isone(ArrayInterface.known_step(typeof(1:4)))
186189
end
187190

0 commit comments

Comments
 (0)