diff --git a/base/array.jl b/base/array.jl index b8a1cbd378e02..c94511aaf8304 100644 --- a/base/array.jl +++ b/base/array.jl @@ -583,8 +583,15 @@ function collect_to!(dest::AbstractArray{T}, itr, offs, st) where T end function grow_to!(dest, itr) - out = grow_to!(empty(dest, Union{}), itr, start(itr)) - return isempty(out) ? dest : out + st = start(itr) + if done(itr, st) + return dest + else + v1, st = next(itr, st) + dest2 = empty(dest, typeof(v1)) + push!(dest2, v1) + return grow_to!(dest2, itr, st) + end end function grow_to!(dest, itr, st) diff --git a/test/functional.jl b/test/functional.jl index d7b9026ea61cb..da620d2b9960f 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -36,6 +36,9 @@ end @test isa(map(Integer, Any[1, 2]), Vector{Int}) @test isa(map(Integer, Any[]), Vector{Integer}) +# issue #25433 +@test @inferred(collect(v for v in [1] if v > 0)) isa Vector{Int} + # filter -- array.jl @test isequal(filter(x->(x>1), [0 1 2 3 2 1 0]), [2, 3, 2]) # TODO: @test_throws isequal(filter(x->x+1, [0 1 2 3 2 1 0]), [2, 3, 2])