From 3c662dc8e9cd5744cfb6d27946453968c00a8d70 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 8be343e4060d4..e22fe75ce31b5 100644 --- a/base/iterators.jl +++ b/base/iterators.jl @@ -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() = () diff --git a/test/iterators.jl b/test/iterators.jl index bbcd81ddea82a..fc3685ed4314b 100644 --- a/test/iterators.jl +++ b/test/iterators.jl @@ -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