File tree 2 files changed +26
-3
lines changed 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -1094,10 +1094,9 @@ end
1094
1094
1095
1095
@inline peek (s:: Stateful , sentinel= nothing ) = s. nextvalstate != = nothing ? s. nextvalstate[1 ] : sentinel
1096
1096
@inline iterate (s:: Stateful , state= nothing ) = s. nextvalstate === nothing ? nothing : (popfirst! (s), nothing )
1097
- IteratorSize (:: Type{Stateful{VS,T}} where VS) where {T} =
1098
- isa (IteratorSize (T), SizeUnknown) ? SizeUnknown () : HasLength ()
1097
+ IteratorSize (:: Type{Stateful{T,VS}} ) where {T,VS} = IteratorSize (T) isa HasShape ? HasLength () : IteratorSize (T)
1099
1098
eltype (:: Type{Stateful{T, VS}} where VS) where {T} = eltype (T)
1100
- IteratorEltype (:: Type{Stateful{VS,T}} where VS ) where {T} = IteratorEltype (T)
1099
+ IteratorEltype (:: Type{Stateful{T,VS}} ) where {T,VS } = IteratorEltype (T)
1101
1100
length (s:: Stateful ) = length (s. itr) - s. taken
1102
1101
1103
1102
end
Original file line number Diff line number Diff line change 549
549
@test ps isa Iterators. Pairs
550
550
@test collect (ps) == [1 => :a , 2 => :b ]
551
551
end
552
+
553
+ @testset " Stateful fix #30643" begin
554
+ @test Base. IteratorSize (1 : 10 ) isa Base. HasShape
555
+ a = Iterators. Stateful (1 : 10 )
556
+ @test Base. IteratorSize (a) isa Base. HasLength
557
+ @test length (a) == 10
558
+ @test length (collect (a)) == 10
559
+ @test length (a) == 0
560
+ b = Iterators. Stateful (Iterators. take (1 : 10 ,3 ))
561
+ @test Base. IteratorSize (b) isa Base. HasLength
562
+ @test length (b) == 3
563
+ @test length (collect (b)) == 3
564
+ @test length (b) == 0
565
+ c = Iterators. Stateful (Iterators. countfrom (1 ))
566
+ @test Base. IteratorSize (c) isa Base. IsInfinite
567
+ @test length (Iterators. take (c,3 )) == 3
568
+ @test length (collect (Iterators. take (c,3 ))) == 3
569
+ d = Iterators. Stateful (Iterators. filter (isodd,1 : 10 ))
570
+ @test Base. IteratorSize (d) isa Base. SizeUnknown
571
+ @test length (collect (Iterators. take (d,3 ))) == 3
572
+ @test length (collect (d)) == 2
573
+ @test length (collect (d)) == 0
574
+ end
575
+
You can’t perform that action at this time.
0 commit comments