From 5ceb68504824c924c3cd0c596486cffaa219d1bd Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 6 Jan 2018 16:07:08 -0500 Subject: [PATCH] fix #25433, make `grow_to!` more inferrable --- base/array.jl | 11 +++++++++-- test/functional.jl | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/base/array.jl b/base/array.jl index 980880fb1aea6..d40eb04b06d47 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])