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 6, 2022
1 parent 331d0a7 commit 2226a01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ end

function copyto!(dest::AbstractArray, dstart::Integer, src)
i = Int(dstart)
if haslength(src)
if haslength(src) && length(dest) > 0
checkbounds(dest, i)
checkbounds(dest, i + length(src) - 1)
for x in src
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_broken copyto!([1,2], 1, ()) == [1,2]
end

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

0 comments on commit 2226a01

Please sign in to comment.