Skip to content

Commit 03abc45

Browse files
authored
Fix reduce(vcat,...) type inference (#40277) (#40294)
1 parent c3d84ce commit 03abc45

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
@@ -1490,7 +1490,7 @@ AbstractVecOrTuple{T} = Union{AbstractVector{<:T}, Tuple{Vararg{T}}}
14901490

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

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

test/abstractarray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,3 +1280,9 @@ end
12801280
@test Int[0 t...; t... 0] == [0 1 2; 1 2 0]
12811281
@test_throws ArgumentError Int[t...; 3 4 5]
12821282
end
1283+
1284+
@testset "reduce(vcat, ...) inferrence #40277" begin
1285+
x_vecs = ([5, ], [1.0, 2.0, 3.0])
1286+
@test @inferred(reduce(vcat, x_vecs)) == [5.0, 1.0, 2.0, 3.0]
1287+
@test @inferred(reduce(vcat, ([10.0], [20.0], Bool[]))) == [10.0, 20.0]
1288+
end

0 commit comments

Comments
 (0)