From 2d822a5977e5255602df67c7a54b784afa492989 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 18 Oct 2017 17:23:54 -0400 Subject: [PATCH] bugfix in collect(A) for zero-dimensional array Ref #24187 (cherry picked from commit c59b8b184e10805a23ebc1e0702e0199147afbb1) --- base/array.jl | 2 +- test/abstractarray.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/base/array.jl b/base/array.jl index 633dfed5c1469..36625e29f6d20 100644 --- a/base/array.jl +++ b/base/array.jl @@ -445,7 +445,7 @@ function _collect(cont, itr, ::HasEltype, isz::SizeUnknown) return a end -_collect_indices(::Tuple{}, A) = copy!(Vector{eltype(A)}(), A) +_collect_indices(::Tuple{}, A) = copy!(Array{eltype(A)}(), A) _collect_indices(indsA::Tuple{Vararg{OneTo}}, A) = copy!(Array{eltype(A)}(length.(indsA)), A) function _collect_indices(indsA, A) diff --git a/test/abstractarray.jl b/test/abstractarray.jl index 8bad4bb84a6b2..94d301eb58873 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -841,3 +841,8 @@ end @testset "checkbounds_indices method ambiguities #20989" begin @test Base.checkbounds_indices(Bool, (1:1,), ([CartesianIndex(1)],)) end + +@testset "zero-dimensional copy" begin + Z = Array{Int}(); Z[] = 17 + @test Z == collect(Z) == copy(Z) +end