diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 933c542d..b05c646b 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -681,7 +681,12 @@ end copyto!(dest[:, i], unpack_voa(bc, i)) else unpacked = unpack_voa(bc, i) - dest[:, i] = unpacked.f(unpacked.args...) + value = unpacked.f(unpacked.args...) + dest[:, i] = if value isa Number && dest[:, i] isa AbstractArray + fill(value, StaticArraysCore.similar_type(dest[:, i])) + else + value + end end end dest diff --git a/test/interface_tests.jl b/test/interface_tests.jl index cba4727a..985de004 100644 --- a/test/interface_tests.jl +++ b/test/interface_tests.jl @@ -149,3 +149,12 @@ function f!(z,zz) end f!(z,zz) @test (@allocated f!(z,zz)) == 0 + +z .= 0.1 +@test z == VectorOfArray([fill(0.1, SVector{2, Float64}), fill(0.1, SVector{2, Float64})]) + +function f2!(z) + z .= 0.1 +end +f2!(z) +@test (@allocated f2!(z)) == 0