Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #25433, make grow_to! more inferrable #25434

Merged
merged 1 commit into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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