Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #16519 by adding missing convert methods #17848

Merged
merged 1 commit into from
Aug 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,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

Expand Down
12 changes: 12 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

function test_in_bounds(::Type{TestAbstractArray})
Expand Down