diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 1e604fa2797108..392872570b802c 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -92,6 +92,7 @@ linearindices(A::AbstractVector) = (@_inline_meta; indices1(A)) eltype{T}(::Type{AbstractArray{T}}) = T eltype{T,N}(::Type{AbstractArray{T,N}}) = T elsize{T}(::AbstractArray{T}) = sizeof(T) + """ ndims(A::AbstractArray) -> Integer @@ -991,6 +992,11 @@ replace_in_print_matrix(A::AbstractMatrix,i::Integer,j::Integer,s::AbstractStrin replace_in_print_matrix(A::AbstractVector,i::Integer,j::Integer,s::AbstractString) = s ## Concatenation ## +eltypeof(x) = typeof(x) +eltypeof(x::AbstractArray) = eltype(x) + +promote_eltypeof() = Bottom +promote_eltypeof(v1, vs...) = promote_type(eltypeof(v1), promote_eltypeof(vs...)) promote_eltype() = Bottom promote_eltype(v1, vs...) = promote_type(eltype(v1), promote_eltype(vs...)) @@ -1136,7 +1142,7 @@ _cs(d, concat, a, b) = concat ? (a + b) : (a == b ? a : throw(DimensionMismatch( dims2cat{n}(::Type{Val{n}}) = ntuple(i -> (i == n), Val{n}) dims2cat(dims) = ntuple(i -> (i in dims), maximum(dims)) -cat(dims, X...) = cat_t(dims, promote_eltype(X...), X...) +cat(dims, X...) = cat_t(dims, promote_eltypeof(X...), X...) function cat_t(dims, T::Type, X...) catdims = dims2cat(dims) diff --git a/test/abstractarray.jl b/test/abstractarray.jl index 9bdc94ab631ca4..ee49a01b79954a 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -567,6 +567,8 @@ function test_cat(::Type{TestAbstractArray}) # 13665, 19038 @test @inferred(hcat([1.0 2.0], 3))::Array{Float64,2} == [1.0 2.0 3.0] @test @inferred(vcat([1.0, 2.0], 3))::Array{Float64,1} == [1.0, 2.0, 3.0] + + @test @inferred(vcat(["a"], "b"))::Vector{String} == ["a", "b"] end function test_ind2sub(::Type{TestAbstractArray})