Skip to content

Commit

Permalink
Fix reduce(vcat,...) type inference (#40277) (#40294)
Browse files Browse the repository at this point in the history
(cherry picked from commit 03abc45)
  • Loading branch information
dlfivefifty authored and KristofferC committed Apr 4, 2021
1 parent 281acc3 commit 40f0ecd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ AbstractVecOrTuple{T} = Union{AbstractVector{<:T}, Tuple{Vararg{T}}}

_typed_vcat_similar(V, ::Type{T}, n) where T = similar(V[1], T, n)
_typed_vcat(::Type{T}, V::AbstractVecOrTuple{AbstractVector}) where T =
_typed_vcat!(_typed_vcat_similar(V, T, mapreduce(length, +, V)), V)
_typed_vcat!(_typed_vcat_similar(V, T, sum(map(length, V))), V)

function _typed_vcat!(a::AbstractVector{T}, V::AbstractVecOrTuple{AbstractVector}) where T
pos = 1
Expand Down
6 changes: 6 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1230,3 +1230,9 @@ end
@test [1; 1:BigInt(5)] == [1; 1:5]
@test [1:BigInt(5); 1] == [1:5; 1]
end

@testset "reduce(vcat, ...) inferrence #40277" begin
x_vecs = ([5, ], [1.0, 2.0, 3.0])
@test @inferred(reduce(vcat, x_vecs)) == [5.0, 1.0, 2.0, 3.0]
@test @inferred(reduce(vcat, ([10.0], [20.0], Bool[]))) == [10.0, 20.0]
end

0 comments on commit 40f0ecd

Please sign in to comment.