From 371824ef7620c0d64fcb16140709806a588c7a62 Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Thu, 5 Mar 2026 17:18:02 +0100 Subject: [PATCH] fix recursivecopy! for mixed nested VectorOfArray --- src/utils.jl | 8 ++++---- test/utils_test.jl | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 68916f91..4f8b942e 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -95,12 +95,12 @@ function recursivecopy!( end function recursivecopy!(b::AbstractVectorOfArray, a::AbstractVectorOfArray) - if ArrayInterface.ismutable(eltype(b.u)) - @inbounds for i in eachindex(b.u, a.u) + @inbounds for i in eachindex(b.u, a.u) + if ArrayInterface.ismutable(b.u[i]) || b.u[i] isa AbstractVectorOfArray recursivecopy!(b.u[i], a.u[i]) + else + b.u[i] = recursivecopy(a.u[i]) end - else - copyto!(b.u, a.u) end return b end diff --git a/test/utils_test.jl b/test/utils_test.jl index d3bb349d..07ba9df5 100644 --- a/test/utils_test.jl +++ b/test/utils_test.jl @@ -139,6 +139,16 @@ end @test u1.u[2] == [2.0, 2.0] @test u1.u[1] isa SVector @test u1.u[2] isa SVector + + # mixed/nested partition types create a Union eltype for `u`. + # recursivecopy! must not fall back to a shallow copy in this case. + a = VectorOfArray([ones(2), VectorOfArray([1.0, 1.0])]) + b = recursivecopy(a) + recursivecopy!(b, a) + @test !(b.u[1] === a.u[1]) + @test !(b.u[2] === a.u[2]) + b.u[1][1] = 99.0 + @test a.u[1][1] == 1.0 end # Test recursivefill! with immutable StaticArrays (issue #461)