From febc11f9d4e28714e5b1c02a996cfe9c781de71b 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 bdbcbe4d081a4..a9431197932dd 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 a07e631e639f9..566dd44b8dcd9 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