Skip to content

Commit

Permalink
fix #23107, ensure Array constructor always makes new arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 28, 2017
1 parent ff706aa commit 6d904da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,12 @@ convert(::Type{Array{T,n}}, x::AbstractArray{S,n}) where {T,n,S} = copy!(Array{T

promote_rule(a::Type{Array{T,n}}, b::Type{Array{S,n}}) where {T,n,S} = el_same(promote_type(T,S), a, b)

# constructors should make copies

Array(x::Array) = copy(x)
Array{T}(x::Array{T}) where {T} = copy(x)
Array{T,N}(x::Array{T,N}) where {T,N} = copy(x)

## copying iterators to containers

"""
Expand Down
6 changes: 6 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ using TestHelpers.OAs
@test ndims(a) == 5
@test a[2,1,2,2,1] == b[14]
@test a[2,2,2,2,2] == b[end]

# issue #23107
a = [1,2,3]
@test typeof(a)(a) !== a
@test Array(a) !== a
@test Array{eltype(a)}(a) !== a
end
@testset "reshaping SubArrays" begin
a = collect(reshape(1:5, 1, 5))
Expand Down

0 comments on commit 6d904da

Please sign in to comment.