Skip to content

Commit

Permalink
Fix isdone for empty product iterators, fixes #43921 (#43947)
Browse files Browse the repository at this point in the history
* Fix the issue #43921

* add a test

Co-authored-by: Kristoffer <[email protected]>
(cherry picked from commit b8a77da)
  • Loading branch information
sasi591 authored and KristofferC committed Dec 14, 2022
1 parent 9bcb6c6 commit a9a234c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ iterate(::ProductIterator{Tuple{}}, state) = nothing
done1 === true || return done1 # false or missing
return _pisdone(tail(iters), tail(states)) # check tail
end
@inline isdone(::ProductIterator{Tuple{}}, states) = true
@inline isdone(P::ProductIterator, states) = _pisdone(P.iterators, states)

@inline _piterate() = ()
Expand Down
8 changes: 8 additions & 0 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -902,3 +902,11 @@ end
@test last(Iterators.map(identity, 1:3)) == 3
@test last(Iterators.filter(iseven, (Iterators.map(identity, 1:3)))) == 2
end

@testset "empty product iterators" begin
v = nothing
for (z,) in zip(Iterators.product())
v = z
end
@test v == ()
end

0 comments on commit a9a234c

Please sign in to comment.