diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 4be18766a30e6..cd55b371de5a3 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1119,7 +1119,7 @@ function copyto!(dest::AbstractArray{T1,N}, Rdest::CartesianIndices{N}, if @generated quote @nloops $N i (n->CRsrc.indices[n]) begin - @inbounds @nref($N,dest,n->Rdest.indices[n][i_n+ΔI[n]]) = @nref($N,src,n->Rsrc.indices[n][i_n]) + @inbounds @nref($N,dest,n->Rdest.indices[n][i_n+ΔI[n]]) = @nref($N,src′,n->Rsrc.indices[n][i_n]) end end else diff --git a/test/copy.jl b/test/copy.jl index 654e95dec67d5..04fda36728e62 100644 --- a/test/copy.jl +++ b/test/copy.jl @@ -67,6 +67,10 @@ end @test all(iszero, B) end end + let A = [reshape(1:6, 3, 2);;] + copyto!(A, CartesianIndices((2:3,2)), A, CartesianIndices((2,2))) + @test A[2:3,:] == [1 4;2 5] + end end @testset "shallow and deep copying" begin