Skip to content

Commit 40f0ecd

Browse files
dlfivefiftyKristofferC
authored andcommitted
Fix reduce(vcat,...) type inference (#40277) (#40294)
(cherry picked from commit 03abc45)
1 parent 281acc3 commit 40f0ecd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

base/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ AbstractVecOrTuple{T} = Union{AbstractVector{<:T}, Tuple{Vararg{T}}}
14891489

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

14941494
function _typed_vcat!(a::AbstractVector{T}, V::AbstractVecOrTuple{AbstractVector}) where T
14951495
pos = 1

test/abstractarray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,3 +1230,9 @@ end
12301230
@test [1; 1:BigInt(5)] == [1; 1:5]
12311231
@test [1:BigInt(5); 1] == [1:5; 1]
12321232
end
1233+
1234+
@testset "reduce(vcat, ...) inferrence #40277" begin
1235+
x_vecs = ([5, ], [1.0, 2.0, 3.0])
1236+
@test @inferred(reduce(vcat, x_vecs)) == [5.0, 1.0, 2.0, 3.0]
1237+
@test @inferred(reduce(vcat, ([10.0], [20.0], Bool[]))) == [10.0, 20.0]
1238+
end

0 commit comments

Comments
 (0)