Skip to content

Commit

Permalink
Fix reduce(vcat,...) type inference (JuliaLang#40277) (JuliaLang#40294)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty authored and ElOceanografo committed May 4, 2021
1 parent 566828c commit cf9bca6
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 @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1280,3 +1280,9 @@ 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]
@test @inferred(reduce(vcat, ([10.0], [20.0], Bool[]))) == [10.0, 20.0]
end

0 comments on commit cf9bca6

Please sign in to comment.