diff --git a/base/array.jl b/base/array.jl index 15c354dce6085..b09a7bd4de836 100644 --- a/base/array.jl +++ b/base/array.jl @@ -895,7 +895,7 @@ function getindex end @eval getindex(A::Array, i1::Int) = arrayref($(Expr(:boundscheck)), A, i1) @eval getindex(A::Array, i1::Int, i2::Int, I::Int...) = (@_inline_meta; arrayref($(Expr(:boundscheck)), A, i1, i2, I...)) -# Faster contiguous indexing using copyto! for UnitRange and Colon +# Faster contiguous indexing using copyto! for AbstractUnitRange and Colon function getindex(A::Array, I::AbstractUnitRange{<:Integer}) @_inline_meta @boundscheck checkbounds(A, I) @@ -955,7 +955,7 @@ function setindex!(A::Array, X::AbstractArray, I::AbstractVector{Int}) end # Faster contiguous setindex! with copyto! -function setindex!(A::Array{T}, X::Array{T}, I::UnitRange{Int}) where T +function setindex!(A::Array{T}, X::Array{T}, I::AbstractUnitRange{Int}) where T @_inline_meta @boundscheck checkbounds(A, I) lI = length(I) @@ -1455,7 +1455,7 @@ julia> deleteat!([6, 5, 4, 3, 2, 1], 2) """ deleteat!(a::Vector, i::Integer) = (_deleteat!(a, i, 1); a) -function deleteat!(a::Vector, r::UnitRange{<:Integer}) +function deleteat!(a::Vector, r::AbstractUnitRange{<:Integer}) n = length(a) isempty(r) || _deleteat!(a, first(r), length(r)) return a @@ -1621,7 +1621,7 @@ Remove items at specified indices, and return a collection containing the removed items. Subsequent items are shifted left to fill the resulting gaps. If specified, replacement values from an ordered collection will be spliced in -place of the removed items; in this case, `indices` must be a `UnitRange`. +place of the removed items; in this case, `indices` must be a `AbstractUnitRange`. To insert `replacement` before an index `n` without removing any items, use `splice!(collection, n:n-1, replacement)`. @@ -1629,6 +1629,9 @@ To insert `replacement` before an index `n` without removing any items, use !!! compat "Julia 1.5" Prior to Julia 1.5, `indices` must always be a `UnitRange`. +!!! compat "Julia 1.8" + Prior to Julia 1.8, `indices` must be a `UnitRange` if splicing in replacement values. + # Examples ```jldoctest julia> A = [-1, -2, -3, 5, 4, 3, -1]; splice!(A, 4:3, 2) @@ -1646,7 +1649,7 @@ julia> A -1 ``` """ -function splice!(a::Vector, r::UnitRange{<:Integer}, ins=_default_splice) +function splice!(a::Vector, r::AbstractUnitRange{<:Integer}, ins=_default_splice) v = a[r] m = length(ins) if m == 0