Skip to content

Commit 6d904da

Browse files
committed
fix #23107, ensure Array constructor always makes new arrays
1 parent ff706aa commit 6d904da

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

base/array.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ convert(::Type{Array{T,n}}, x::AbstractArray{S,n}) where {T,n,S} = copy!(Array{T
563563

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

566+
# constructors should make copies
567+
568+
Array(x::Array) = copy(x)
569+
Array{T}(x::Array{T}) where {T} = copy(x)
570+
Array{T,N}(x::Array{T,N}) where {T,N} = copy(x)
571+
566572
## copying iterators to containers
567573

568574
"""

test/arrayops.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ using TestHelpers.OAs
9090
@test ndims(a) == 5
9191
@test a[2,1,2,2,1] == b[14]
9292
@test a[2,2,2,2,2] == b[end]
93+
94+
# issue #23107
95+
a = [1,2,3]
96+
@test typeof(a)(a) !== a
97+
@test Array(a) !== a
98+
@test Array{eltype(a)}(a) !== a
9399
end
94100
@testset "reshaping SubArrays" begin
95101
a = collect(reshape(1:5, 1, 5))

0 commit comments

Comments
 (0)