Skip to content

Commit 025a991

Browse files
committed
Ensure static array constructors create copies
1 parent 0e9ce69 commit 025a991

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/convert.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(::Type{SA})(x::Tuple{Tuple{Tuple{<:Tuple}}}) where {SA <: StaticArray} = error("No precise constructor for $SA found. Length of input was $(length(x[1][1][1])).")
22

33
@inline (::Type{SA})(x...) where {SA <: StaticArray} = SA(x)
4-
@inline (::Type{SA})(a::AbstractArray) where {SA <: StaticArray} = convert(SA, a) # Is this a good idea?
4+
@inline (::Type{SA})(a::StaticArray) where {SA<:StaticArray} = SA(Tuple(a))
5+
@inline (::Type{SA})(a::AbstractArray) where {SA <: StaticArray} = convert(SA, a)
56

67
# this covers most conversions and "statically-sized reshapes"
78
@inline convert(::Type{SA}, sa::StaticArray) where {SA<:StaticArray} = SA(Tuple(sa))

test/MVector.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
@test MVector((1,)).data === (1,)
1717
@test MVector((1.0,)).data === (1.0,)
1818

19+
# Constructors should create a copy (#335)
20+
v = MVector(1,2)
21+
@test MVector(v) !== v && MVector(v) == v
22+
1923
@test ((@MVector [1.0])::MVector{1}).data === (1.0,)
2024
@test ((@MVector [1, 2, 3])::MVector{3}).data === (1, 2, 3)
2125
@test ((@MVector Float64[1,2,3])::MVector{3}).data === (1.0, 2.0, 3.0)

0 commit comments

Comments
 (0)