Skip to content

Commit

Permalink
fix an empty case, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Jan 13, 2022
1 parent d583640 commit 1b0140a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 2 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,8 @@ end

function copyto!(dest::AbstractArray, dstart::Integer, src)
i = Int(dstart)
if haslength(src)
checkbounds(dest, i)
checkbounds(dest, i + length(src) - 1)
if haslength(src) && length(dest) > 0
@boundscheck checkbounds(dest, i:(i + length(src) - 1))
for x in src
@inbounds dest[i] = x
i += 1
Expand Down
10 changes: 10 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,16 @@ end
@test_throws ArgumentError LinearAlgebra.copy_transpose!(a,2:3,1:3,b,1:5,2:7)
end

@testset "empty copyto!" begin
@test isempty(copyto!(Int[], ()))
@test isempty(copyto!(Int[], Int[]))
@test copyto!([1,2], ()) == [1,2]

@test isempty(copyto!(Int[], 1, ()))
@test isempty(copyto!(Int[], 1, Int[]))
@test copyto!([1,2], 1, ()) == [1,2]
end

module RetTypeDecl
using Test
import Base: +, *, broadcast, convert
Expand Down

0 comments on commit 1b0140a

Please sign in to comment.