Skip to content

Commit 8eec8a8

Browse files
authored
copy: return a value of the same type (#20)
Before this the return type was always `Box`.
1 parent a400123 commit 8eec8a8

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/ZeroDimensionalArrays.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ function convert_from_other_array(::Type{Arr}, a::AbstractArray{<:Any, 0}) where
9595
convert_from_other_array_to_given_eltype(Arr, T, a)
9696
end
9797

98+
function Base.copy(a::ZeroDimensionalArray)
99+
Arr = typeof(a)
100+
convert_from_other_array(Arr, a)
101+
end
102+
98103
for Arr (
99104
ZeroDimArray,
100105
Box,

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ using Aqua: Aqua
2929
@test !(isassigned(Arr(0.3), 2))
3030
@test (@inferred similar(Arr(0.3))) isa Box{Float64}
3131
@test (@inferred similar(Arr(0.3), Float32)) isa Box{Float32}
32+
@test (@inferred copy(Arr(0.3))) isa Arr{Float64}
33+
@test (@inferred copy(Arr{AbstractFloat}(0.3))) isa Arr{AbstractFloat}
34+
@test let a = Arr(0.3)
35+
a == copy(a)
36+
end
3237
@test fill(0.3) == Arr(0.3)
3338
@test Arr(0.3) == Arr(0.3)
3439
@test all(@inferred Arr(0.3) .== Arr(0.3))

0 commit comments

Comments
 (0)