Skip to content

Commit

Permalink
fix #25433, make grow_to! more inferrable
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jan 6, 2018
1 parent 7b82e50 commit 5ceb685
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 5ceb685

Please sign in to comment.