Strange behavior with list comprehensions using Iterators.Stateful

I’m having trouble to understand the following behavior of Iterators.Stateful. This is as expected

julia> for a in Iterators.Stateful([1,2,3])
             print(a)
         end
123

But this seems strange:

julia> [a for a in Iterators.Stateful([1,2,3])]
2-element Array{Int64,1}:
 1
 2
julia> [a for a in Iterators.Stateful([1])]
ERROR: BoundsError: attempt to access 0-element Array{Int64,1} at index [1]

Is this a bug, or is there something I don’t understand here?

Looking at the code

The iterate call at

makes length(itr) go from 1 to 0.

Then in _array_for(typeof(v1), itr.iter, isz):

a length 0 vector is allocated which is then tried to get assigned into:

I’m guessing the axis / length should be computed before the call to iterate.