Skip to content

Commit ae5cb8d

Browse files
committed
force push! and unshift! need at least one item
1 parent 31c12af commit ae5cb8d

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

base/abstractarray.jl

-2
Original file line numberDiff line numberDiff line change
@@ -1453,10 +1453,8 @@ end
14531453

14541454
# multi-item push!, unshift! (built on top of type-specific 1-item version)
14551455
# (note: must not cause a dispatch loop when 1-item case is not defined)
1456-
push!(A) = A
14571456
push!(A, a, b) = push!(push!(A, a), b)
14581457
push!(A, a, b, c...) = push!(push!(A, a, b), c...)
1459-
unshift!(A) = A
14601458
unshift!(A, a, b) = unshift!(unshift!(A, b), a)
14611459
unshift!(A, a, b, c...) = unshift!(unshift!(A, c...), a, b)
14621460

doc/stdlib/collections.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ Dequeues
800800

801801
.. function:: push!(collection, items...) -> collection
802802

803-
Insert zero or more ``items`` at the end of ``collection``.
803+
Insert one or more ``items`` at the end of ``collection``.
804804

805805
.. doctest::
806806

@@ -846,7 +846,7 @@ Dequeues
846846

847847
.. function:: unshift!(collection, items...) -> collection
848848

849-
Insert zero or more ``items`` at the beginning of ``collection``.
849+
Insert one or more ``items`` at the beginning of ``collection``.
850850

851851
.. doctest::
852852

test/arrayops.jl

+6
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,12 @@ A = [NaN]; B = [NaN]
832832
@test isequal(A,B)
833833
@test A!==B
834834

835+
# test that single arugment push!, unshift! are not defined
836+
let A = []
837+
@test_throws MethodError push!(a)
838+
@test_throws MethodError unshift!(a)
839+
end
840+
835841
# complete testsuite for reducedim
836842

837843
# Inferred types

0 commit comments

Comments
 (0)