diff --git a/base/array.jl b/base/array.jl index 2e0f5b4feb98b..49b9758424f59 100644 --- a/base/array.jl +++ b/base/array.jl @@ -226,6 +226,9 @@ end ## Conversions ## +convert{T}(::Type{Vector}, x::AbstractVector{T}) = convert(Vector{T}, x) +convert{T}(::Type{Matrix}, x::AbstractMatrix{T}) = convert(Matrix{T}, x) + convert{T,n}(::Type{Array{T}}, x::Array{T,n}) = x convert{T,n}(::Type{Array{T,n}}, x::Array{T,n}) = x diff --git a/test/abstractarray.jl b/test/abstractarray.jl index db26e0099f896..807e5da5a7398 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -405,7 +405,19 @@ function test_primitives{T}(::Type{T}, shape, ::Type{TestAbstractArray}) # convert{T, N}(::Type{Array}, A::AbstractArray{T, N}) X = [1:10...] + Y = [1 2; 3 4] @test convert(Array, X) == X + @test convert(Array, Y) == Y + + # convert{T}(::Type{Vector}, A::AbstractVector{T}) + @test convert(Vector, X) == X + @test convert(Vector, view(X, 2:4)) == [2,3,4] + @test_throws MethodError convert(Vector, Y) + + # convert{T}(::Type{Matrix}, A::AbstractMatrix{T}) + @test convert(Matrix, Y) == Y + @test convert(Matrix, view(Y, 1:2, 1:2)) == Y + @test_throws MethodError convert(Matrix, X) end let