Skip to content

Commit 1b0140a

Browse files
committed
fix an empty case, add tests
1 parent d583640 commit 1b0140a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

base/abstractarray.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,8 @@ end
904904

905905
function copyto!(dest::AbstractArray, dstart::Integer, src)
906906
i = Int(dstart)
907-
if haslength(src)
908-
checkbounds(dest, i)
909-
checkbounds(dest, i + length(src) - 1)
907+
if haslength(src) && length(dest) > 0
908+
@boundscheck checkbounds(dest, i:(i + length(src) - 1))
910909
for x in src
911910
@inbounds dest[i] = x
912911
i += 1

test/arrayops.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,16 @@ end
21222122
@test_throws ArgumentError LinearAlgebra.copy_transpose!(a,2:3,1:3,b,1:5,2:7)
21232123
end
21242124

2125+
@testset "empty copyto!" begin
2126+
@test isempty(copyto!(Int[], ()))
2127+
@test isempty(copyto!(Int[], Int[]))
2128+
@test copyto!([1,2], ()) == [1,2]
2129+
2130+
@test isempty(copyto!(Int[], 1, ()))
2131+
@test isempty(copyto!(Int[], 1, Int[]))
2132+
@test copyto!([1,2], 1, ()) == [1,2]
2133+
end
2134+
21252135
module RetTypeDecl
21262136
using Test
21272137
import Base: +, *, broadcast, convert

0 commit comments

Comments
 (0)