Skip to content

Commit 0c4ed25

Browse files
fix: do not assume AbstractVectorOfArray is mutable in Base.zero
1 parent 600a9b5 commit 0c4ed25

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/vector_of_array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ end
521521

522522
function Base.zero(VA::AbstractVectorOfArray)
523523
val = copy(VA)
524-
val.u = zero.(VA.u)
524+
val.u .= zero.(VA.u)
525525
return val
526526
end
527527

test/interface_tests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,13 @@ end
269269
f3!(z, zz)
270270
@test z == VectorOfArray([fill(4, SVector{2, Float64}), fill(2, SVector{2, Float64})])
271271
@test (@allocated f3!(z, zz)) == 0
272+
273+
struct ImmutableVectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N, A}
274+
u::A # A <: AbstractArray{<: AbstractArray{T, N - 1}}
275+
end
276+
277+
@testset "Base.zero does not assume mutable struct" begin
278+
voa = ImmutableVectorOfArray([ones(3), 2ones(3)])
279+
zvoa = zero(voa)
280+
@test voa.u[1] == voa.u[2] == zeros(3)
281+
end

0 commit comments

Comments
 (0)