From 6a0934322151de8feb85b74f324ef2e8b5e5de29 Mon Sep 17 00:00:00 2001 From: Sasank <56350738+sasi591@users.noreply.github.com> Date: Thu, 3 Nov 2022 16:17:53 +0530 Subject: [PATCH] Fix isdone for empty product iterators, fixes #43921 (#43947) * Fix the issue #43921 * add a test Co-authored-by: Kristoffer (cherry picked from commit b8a77daf3832d4134ad46327049772a663e2643d) --- base/iterators.jl | 1 + test/iterators.jl | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/base/iterators.jl b/base/iterators.jl index 3e339c59bebcb3..e14880b6c0a33f 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -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() = () diff --git a/test/iterators.jl b/test/iterators.jl index 0a038698ea07cb..adf8d79e4429e6 100644 --- a/test/iterators.jl +++ b/test/iterators.jl @@ -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