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 21, 2022
1 parent d156ef1 commit 84cb211
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 @@ -993,6 +993,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 @@ -859,3 +859,11 @@ end
@test cumprod(x + 1 for x in 1:3) == [2, 6, 24]
@test accumulate(+, (x^2 for x in 1:3); init=100) == [101, 105, 114]
end

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

0 comments on commit 84cb211

Please sign in to comment.