From fd77ae66669ed9ae568ce7bf67ff40f3a544e34d Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Thu, 1 Apr 2021 08:48:49 -0400 Subject: [PATCH 1/3] Fix reduce(vcat,...) type inference (#40277) --- base/abstractarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 724b23c6e8ca3..15715ac57eb3e 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1490,7 +1490,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 From 4f1aad2bc9a5abe5a92f422af79e3fcf53bf7a77 Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Thu, 1 Apr 2021 08:51:34 -0400 Subject: [PATCH 2/3] Update abstractarray.jl --- test/abstractarray.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/abstractarray.jl b/test/abstractarray.jl index dd24dc28364c7..7c18214c03c55 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -1280,3 +1280,8 @@ end @test Int[0 t...; t... 0] == [0 1 2; 1 2 0] @test_throws ArgumentError Int[t...; 3 4 5] 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] +end From 4d06c905461101b4572b28da3b98c625621a00c2 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Fri, 2 Apr 2021 16:21:12 +0200 Subject: [PATCH 3/3] add another test --- test/abstractarray.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/abstractarray.jl b/test/abstractarray.jl index 7c18214c03c55..6933aa0a2da00 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -1284,4 +1284,5 @@ 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