diff --git a/base/iterator.jl b/base/iterator.jl index 977defd56f58d..853914b2ce2ae 100644 --- a/base/iterator.jl +++ b/base/iterator.jl @@ -10,7 +10,8 @@ enumerate(itr) = Enumerate(itr) length(e::Enumerate) = length(e.itr) start(e::Enumerate) = (1, start(e.itr)) function next(e::Enumerate, state) - (state[1],next(e.itr,state[2])[1]), (state[1]+1,next(e.itr,state[2])[2]) + n = next(e.itr,state[2]) + (state[1],n[1]), (state[1]+1,n[2]) end done(e::Enumerate, state) = done(e.itr, state[2]) diff --git a/test/functional.jl b/test/functional.jl index b132ec44c702e..5e2ad882d5aec 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -47,3 +47,11 @@ end # zip and filter iterators # issue #4718 @test collect(filter(x->x[1], zip([true, false, true, false],"abcd"))) == {(true,'a'),(true,'c')} + +# enumerate (issue #6284) +let b = IOBuffer("1\n2\n3\n"), a = {} + for (i,x) in enumerate(eachline(b)) + push!(a, (i,x)) + end + @test a == {(1,"1\n"),(2,"2\n"),(3,"3\n")} +end