Skip to content

Commit 5563a1e

Browse files
committed
fix an empty case, add tests
1 parent c72a61a commit 5563a1e

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
@@ -910,9 +910,8 @@ end
910910

911911
function copyto!(dest::AbstractArray, dstart::Integer, src)
912912
i = Int(dstart)
913-
if haslength(src)
914-
checkbounds(dest, i)
915-
checkbounds(dest, i + length(src) - 1)
913+
if haslength(src) && length(dest) > 0
914+
@boundscheck checkbounds(dest, i:(i + length(src) - 1))
916915
for x in src
917916
@inbounds dest[i] = x
918917
i += 1

test/arrayops.jl

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

2108+
@testset "empty copyto!" begin
2109+
@test isempty(copyto!(Int[], ()))
2110+
@test isempty(copyto!(Int[], Int[]))
2111+
@test copyto!([1,2], ()) == [1,2]
2112+
2113+
@test isempty(copyto!(Int[], 1, ()))
2114+
@test isempty(copyto!(Int[], 1, Int[]))
2115+
@test copyto!([1,2], 1, ()) == [1,2]
2116+
end
2117+
21082118
module RetTypeDecl
21092119
using Test
21102120
import Base: +, *, broadcast, convert

0 commit comments

Comments
 (0)