Skip to content

Commit ef95ab9

Browse files
authored
Fix length(::Type{<:NDIndex}) (#61)
see #55 (comment)
1 parent 0a5b294 commit ef95ab9

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Static"
22
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
33
authors = ["chriselrod", "ChrisRackauckas", "Tokazama"]
4-
version = "0.6.4"
4+
version = "0.6.5"
55

66
[deps]
77
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"

src/ndindex.jl

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

6666
# length
6767
Base.length(@nospecialize(x::NDIndex))::Int = length(Tuple(x))
68-
Base.length(@nospecialize(T::Type{<:NDIndex}))::Int = @inbounds(T.parameters[1])
68+
Base.length(::Type{<:NDIndex{N}}) where {N} = N
6969

7070
# indexing
7171
@propagate_inbounds function Base.getindex(x::NDIndex{N,T}, i::Int)::Int where {N,T}

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ using Test
338338
@test @inferred(Base.IteratorsMD.split(x, Val(2))) === (NDIndex(1, 2), NDIndex(3,))
339339
@test @inferred(length(x)) === 3
340340
@test @inferred(length(typeof(x))) === 3
341+
NDIndex2{I<:Tuple{Vararg{Union{StaticInt,Int},2}}} = NDIndex{2, I}
342+
@test length(NDIndex2) === 2
341343
@test @inferred(y[2]) === 2
342344
@test @inferred(y[static(2)]) === static(2)
343345

0 commit comments

Comments
 (0)