Skip to content

Commit

Permalink
Merge pull request #25434 from JuliaLang/jb/fix25433
Browse files Browse the repository at this point in the history
fix #25433, make `grow_to!` more inferrable
  • Loading branch information
StefanKarpinski authored Jan 7, 2018
2 parents 7b4ebf4 + 5ceb685 commit ec8064c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit ec8064c

Please sign in to comment.