From c0bb48b8cf3b6dc577788d932d6c75de3792dc73 Mon Sep 17 00:00:00 2001 From: erich-9 Date: Sun, 3 Mar 2024 04:14:28 +0100 Subject: [PATCH] Always return a value in 1-d circshift! of abstractarray.jl (#53554) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sukera <11753998+Seelengrab@users.noreply.github.com> Co-authored-by: Mosè Giordano --- base/abstractarray.jl | 4 ++-- test/arrayops.jl | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index bdbcbe4d081a42..a9431197932dde 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -3656,9 +3656,9 @@ end ## 1-d circshift ## function circshift!(a::AbstractVector, shift::Integer) n = length(a) - n == 0 && return + n == 0 && return a shift = mod(shift, n) - shift == 0 && return + shift == 0 && return a l = lastindex(a) reverse!(a, firstindex(a), l-shift) reverse!(a, l-shift+1, lastindex(a)) diff --git a/test/arrayops.jl b/test/arrayops.jl index a07e631e639f92..566dd44b8dcd9e 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -797,6 +797,14 @@ end oa = OffsetVector(copy(a), -1) @test circshift!(oa, 1) === oa @test oa == circshift(OffsetVector(a, -1), 1) + + # 1d circshift! (#53554) + a = [] + @test circshift!(a, 1) === a + @test circshift!(a, 1) == [] + a = [1:5;] + @test circshift!(a, 10) === a + @test circshift!(a, 10) == 1:5 end @testset "circcopy" begin