diff --git a/base/generator.jl b/base/generator.jl index 203d1dbba1199..e5b3e46f88361 100644 --- a/base/generator.jl +++ b/base/generator.jl @@ -51,6 +51,7 @@ length(g::Generator) = length(g.iter) size(g::Generator) = size(g.iter) axes(g::Generator) = axes(g.iter) ndims(g::Generator) = ndims(g.iter) +keys(g::Generator) = keys(g.iter) ## iterator traits diff --git a/test/functional.jl b/test/functional.jl index f2d6d4a898ede..c9b0b270baeb7 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -134,6 +134,11 @@ let gen = ((x,y) for x in 1:10, y in 1:10 if x % 2 == 0 && y % 2 == 0), @test collect(gen) == collect(gen2) end +# keys of a generator for find* and arg* (see #34678) +@test keys(x^2 for x in -1:0.5:1) == 1:5 +@test findall(!iszero, x^2 for x in -1:0.5:1) == [1, 2, 4, 5] +@test argmin(x^2 for x in -1:0.5:1) == 3 + # inference on vararg generator of a type (see #22907 comments) let f(x) = collect(Base.Generator(=>, x, x)) @test @inferred(f((1,2))) == [1=>1, 2=>2]