From 02fba855595f5f4ea1dc12ec3fe1cff4926ef959 Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Fri, 8 Sep 2017 16:44:52 +0200 Subject: [PATCH] Rename Range to AbstractRange (#23570) * Rename Range to AbstractRange * Change "a" to "an" before AbstractRange * Update syntax files under contrib/ Rename Range to AbstractRange, and Range1 to UnitRange (which should have been done before). * Add deprecation and NEWS entry * Fix incorrect replacements * Address review comments --- NEWS.md | 2 + base/abstractarray.jl | 32 +++---- base/array.jl | 4 +- base/complex.jl | 2 +- base/dates/arithmetic.jl | 2 +- base/dates/ranges.jl | 6 +- base/deprecated.jl | 6 +- base/exports.jl | 2 +- base/hashing.jl | 2 +- base/linalg/blas.jl | 8 +- base/linalg/dense.jl | 4 +- base/linalg/matmul.jl | 4 +- base/linalg/transpose.jl | 4 +- base/range.jl | 108 +++++++++++------------ base/reduce.jl | 2 +- base/replutil.jl | 4 +- base/reshapedarray.jl | 2 +- base/set.jl | 2 +- base/sort.jl | 14 +-- base/sparse/sparsematrix.jl | 10 +-- base/sparse/sparsevector.jl | 2 +- base/statistics.jl | 6 +- base/strings/basic.jl | 2 +- base/subarray.jl | 8 +- base/twiceprecision.jl | 10 +-- contrib/Julia_Notepad++.xml | 2 +- contrib/julia.hrc | 4 +- contrib/julia.lang | 5 +- contrib/julia.xml | 5 +- doc/src/manual/arrays.md | 2 +- doc/src/manual/control-flow.md | 2 +- doc/src/manual/interfaces.md | 4 +- doc/src/manual/noteworthy-differences.md | 8 +- doc/src/stdlib/collections.md | 6 +- test/TestHelpers.jl | 2 +- test/core.jl | 6 +- test/ranges.jl | 16 ++-- test/sorting.jl | 2 +- test/specificity.jl | 2 +- test/subtype.jl | 4 +- 40 files changed, 161 insertions(+), 157 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8b7a481d5bb5a..66d7885f5f539 100644 --- a/NEWS.md +++ b/NEWS.md @@ -420,6 +420,8 @@ Deprecated or removed * `select`, `select!`, `selectperm` and `selectperm!` have been renamed respectively to `partialsort`, `partialsort!`, `partialsortperm` and `partialsortperm!` ([#23051]). + * The `Range` abstract type has been renamed to `AbstractRange` ([#23570]). + Command-line option changes --------------------------- diff --git a/base/abstractarray.jl b/base/abstractarray.jl index c5847e584038c..bf84de4251aad 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -77,7 +77,7 @@ indices1(A::AbstractArray) = (@_inline_meta; indices(A)[1]) indices1(iter) = OneTo(length(iter)) unsafe_indices(A) = indices(A) -unsafe_indices(r::Range) = (OneTo(unsafe_length(r)),) # Ranges use checked_sub for size +unsafe_indices(r::AbstractRange) = (OneTo(unsafe_length(r)),) # Ranges use checked_sub for size """ linearindices(A) @@ -171,8 +171,8 @@ first(a::AbstractArray) = a[first(eachindex(a))] """ first(coll) -Get the first element of an iterable collection. Returns the start point of a -`Range` even if it is empty. +Get the first element of an iterable collection. Returns the start point of an +`AbstractRange` even if it is empty. # Examples ```jldoctest @@ -194,7 +194,7 @@ end Get the last element of an ordered collection, if it can be computed in O(1) time. This is accomplished by calling [`endof`](@ref) to get the last index. Returns the end -point of a `Range` even if it is empty. +point of an `AbstractRange` even if it is empty. # Examples ```jldoctest @@ -324,7 +324,7 @@ IndexStyle(A::AbstractArray) = IndexStyle(typeof(A)) IndexStyle(::Type{Union{}}) = IndexLinear() IndexStyle(::Type{<:AbstractArray}) = IndexCartesian() IndexStyle(::Type{<:Array}) = IndexLinear() -IndexStyle(::Type{<:Range}) = IndexLinear() +IndexStyle(::Type{<:AbstractRange}) = IndexLinear() IndexStyle(A::AbstractArray, B::AbstractArray) = IndexStyle(IndexStyle(A), IndexStyle(B)) IndexStyle(A::AbstractArray, B::AbstractArray...) = IndexStyle(IndexStyle(A), IndexStyle(B...)) @@ -457,7 +457,7 @@ checkindex(::Type{Bool}, inds::AbstractUnitRange, i) = checkindex(::Type{Bool}, inds::AbstractUnitRange, i::Real) = (first(inds) <= i) & (i <= last(inds)) checkindex(::Type{Bool}, inds::AbstractUnitRange, ::Colon) = true checkindex(::Type{Bool}, inds::AbstractUnitRange, ::Slice) = true -function checkindex(::Type{Bool}, inds::AbstractUnitRange, r::Range) +function checkindex(::Type{Bool}, inds::AbstractUnitRange, r::AbstractRange) @_propagate_inbounds_meta isempty(r) | (checkindex(Bool, inds, first(r)) & checkindex(Bool, inds, last(r))) end @@ -700,8 +700,8 @@ function copy(a::AbstractArray) copymutable(a) end -function copy!(B::AbstractVecOrMat{R}, ir_dest::Range{Int}, jr_dest::Range{Int}, - A::AbstractVecOrMat{S}, ir_src::Range{Int}, jr_src::Range{Int}) where {R,S} +function copy!(B::AbstractVecOrMat{R}, ir_dest::AbstractRange{Int}, jr_dest::AbstractRange{Int}, + A::AbstractVecOrMat{S}, ir_src::AbstractRange{Int}, jr_src::AbstractRange{Int}) where {R,S} if length(ir_dest) != length(ir_src) throw(ArgumentError(string("source and destination must have same size (got ", length(ir_src)," and ",length(ir_dest),")"))) @@ -895,7 +895,7 @@ end getindex(A, inds...) Return a subset of array `A` as specified by `inds`, where each `ind` may be an -`Int`, a `Range`, or a [`Vector`](@ref). See the manual section on +`Int`, an `AbstractRange`, or a [`Vector`](@ref). See the manual section on [array indexing](@ref man-array-indexing) for details. # Examples @@ -1045,14 +1045,14 @@ end ## get (getindex with a default value) ## -RangeVecIntList{A<:AbstractVector{Int}} = Union{Tuple{Vararg{Union{Range, AbstractVector{Int}}}}, - AbstractVector{UnitRange{Int}}, AbstractVector{Range{Int}}, AbstractVector{A}} +RangeVecIntList{A<:AbstractVector{Int}} = Union{Tuple{Vararg{Union{AbstractRange, AbstractVector{Int}}}}, + AbstractVector{UnitRange{Int}}, AbstractVector{AbstractRange{Int}}, AbstractVector{A}} get(A::AbstractArray, i::Integer, default) = checkbounds(Bool, A, i) ? A[i] : default get(A::AbstractArray, I::Tuple{}, default) = similar(A, typeof(default), 0) get(A::AbstractArray, I::Dims, default) = checkbounds(Bool, A, I...) ? A[I...] : default -function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{Range,AbstractVector{Int}}, default::T) where T +function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{AbstractRange,AbstractVector{Int}}, default::T) where T # 1d is not linear indexing ind = findin(I, indices1(A)) X[ind] = A[I[ind]] @@ -1061,7 +1061,7 @@ function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{Range,AbstractVe X[last(ind)+1:last(Xind)] = default X end -function get!(X::AbstractArray{T}, A::AbstractArray, I::Union{Range,AbstractVector{Int}}, default::T) where T +function get!(X::AbstractArray{T}, A::AbstractArray, I::Union{AbstractRange,AbstractVector{Int}}, default::T) where T # Linear indexing ind = findin(I, 1:length(A)) X[ind] = A[I[ind]] @@ -1070,7 +1070,7 @@ function get!(X::AbstractArray{T}, A::AbstractArray, I::Union{Range,AbstractVect X end -get(A::AbstractArray, I::Range, default) = get!(similar(A, typeof(default), index_shape(I)), A, I, default) +get(A::AbstractArray, I::AbstractRange, default) = get!(similar(A, typeof(default), index_shape(I)), A, I, default) # TODO: DEPRECATE FOR #14770 (just the partial linear indexing part) function get!(X::AbstractArray{T}, A::AbstractArray, I::RangeVecIntList, default::T) where T @@ -1559,7 +1559,7 @@ function isequal(A::AbstractArray, B::AbstractArray) if indices(A) != indices(B) return false end - if isa(A,Range) != isa(B,Range) + if isa(A,AbstractRange) != isa(B,AbstractRange) return false end for (a, b) in zip(A, B) @@ -1582,7 +1582,7 @@ function (==)(A::AbstractArray, B::AbstractArray) if indices(A) != indices(B) return false end - if isa(A,Range) != isa(B,Range) + if isa(A,AbstractRange) != isa(B,AbstractRange) return false end for (a, b) in zip(A, B) diff --git a/base/array.jl b/base/array.jl index 194f6f48da2f4..28683a9fe19ce 100644 --- a/base/array.jl +++ b/base/array.jl @@ -30,7 +30,7 @@ elements of type `T`. Alias for [`AbstractArray{T,2}`](@ref). """ const AbstractMatrix{T} = AbstractArray{T,2} const AbstractVecOrMat{T} = Union{AbstractVector{T}, AbstractMatrix{T}} -const RangeIndex = Union{Int, Range{Int}, AbstractUnitRange{Int}} +const RangeIndex = Union{Int, AbstractRange{Int}, AbstractUnitRange{Int}} const DimOrInd = Union{Integer, AbstractUnitRange} const IntOrInd = Union{Int, AbstractUnitRange} const DimsOrInds{N} = NTuple{N,DimOrInd} @@ -789,7 +789,7 @@ function getindex(A::Array, c::Colon) end # This is redundant with the abstract fallbacks, but needed for bootstrap -function getindex(A::Array{S}, I::Range{Int}) where S +function getindex(A::Array{S}, I::AbstractRange{Int}) where S return S[ A[i] for i in I ] end diff --git a/base/complex.jl b/base/complex.jl index 0664f9679c248..07a7cbe317423 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -211,7 +211,7 @@ bswap(z::Complex) = Complex(bswap(real(z)), bswap(imag(z))) isequal(z::Complex, w::Complex) = isequal(real(z),real(w)) & isequal(imag(z),imag(w)) -in(x::Complex, r::Range{<:Real}) = isreal(x) && real(x) in r +in(x::Complex, r::AbstractRange{<:Real}) = isreal(x) && real(x) in r if UInt === UInt64 const h_imag = 0x32a7a07f3e7cd1f9 diff --git a/base/dates/arithmetic.jl b/base/dates/arithmetic.jl index 93d22c5f72119..028a5fa6ff20a 100644 --- a/base/dates/arithmetic.jl +++ b/base/dates/arithmetic.jl @@ -95,4 +95,4 @@ end # AbstractArray{TimeType}, AbstractArray{TimeType} (-)(x::OrdinalRange{T}, y::OrdinalRange{T}) where {T<:TimeType} = collect(x) - collect(y) -(-)(x::Range{T}, y::Range{T}) where {T<:TimeType} = collect(x) - collect(y) +(-)(x::AbstractRange{T}, y::AbstractRange{T}) where {T<:TimeType} = collect(x) - collect(y) diff --git a/base/dates/ranges.jl b/base/dates/ranges.jl index 21b646bd062fe..2a2795102757b 100644 --- a/base/dates/ranges.jl +++ b/base/dates/ranges.jl @@ -43,6 +43,6 @@ Base.start(r::StepRange{<:TimeType}) = 0 Base.next(r::StepRange{<:TimeType}, i::Int) = (r.start + r.step*i, i + 1) Base.done(r::StepRange{<:TimeType,<:Period}, i::Integer) = length(r) <= i -+(x::Period, r::Range{<:TimeType}) = (x + first(r)):step(r):(x + last(r)) -+(r::Range{<:TimeType}, x::Period) = x + r --(r::Range{<:TimeType}, x::Period) = (first(r)-x):step(r):(last(r)-x) ++(x::Period, r::AbstractRange{<:TimeType}) = (x + first(r)):step(r):(x + last(r)) ++(r::AbstractRange{<:TimeType}, x::Period) = x + r +-(r::AbstractRange{<:TimeType}, x::Period) = (first(r)-x):step(r):(last(r)-x) diff --git a/base/deprecated.jl b/base/deprecated.jl index d1a3d05b7820e..51bed516e347a 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -395,7 +395,7 @@ export $ @deprecate is (===) # midpoints of intervals -@deprecate midpoints(r::Range) r[1:length(r)-1] + 0.5*step(r) +@deprecate midpoints(r::AbstractRange) r[1:length(r)-1] + 0.5*step(r) @deprecate midpoints(v::AbstractVector) [0.5*(v[i] + v[i+1]) for i in 1:length(v)-1] @deprecate_binding Filter Iterators.Filter @@ -1149,7 +1149,7 @@ end ## the replacement StepRangeLen also has 4 real-valued fields, which ## makes deprecation tricky. See #20506. -struct Use_StepRangeLen_Instead{T<:AbstractFloat} <: Range{T} +struct Use_StepRangeLen_Instead{T<:AbstractFloat} <: AbstractRange{T} start::T step::T len::T @@ -1754,6 +1754,8 @@ import .Iterators.enumerate @deprecate enumerate(i::IndexLinear, A::AbstractArray) pairs(i, A) @deprecate enumerate(i::IndexCartesian, A::AbstractArray) pairs(i, A) +@deprecate_binding Range AbstractRange + # END 0.7 deprecations # BEGIN 1.0 deprecations diff --git a/base/exports.jl b/base/exports.jl index 608c5f46d0d8f..5bec9d90274bf 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -26,6 +26,7 @@ export # Types AbstractChannel, AbstractMatrix, + AbstractRange, AbstractSet, AbstractUnitRange, AbstractVector, @@ -87,7 +88,6 @@ export PermutedDimsArray, PollingFileWatcher, QuickSort, - Range, RangeIndex, Rational, Regex, diff --git a/base/hashing.jl b/base/hashing.jl index ee4be4d384941..e2847342a8c57 100644 --- a/base/hashing.jl +++ b/base/hashing.jl @@ -76,7 +76,7 @@ hash(x::QuoteNode, h::UInt) = hash(x.value, hash(QuoteNode, h)) # hashing ranges by component at worst leads to collisions for very similar ranges const hashr_seed = UInt === UInt64 ? 0x80707b6821b70087 : 0x21b70087 -function hash(r::Range, h::UInt) +function hash(r::AbstractRange, h::UInt) h += hashr_seed h = hash(first(r), h) h = hash(step(r), h) diff --git a/base/linalg/blas.jl b/base/linalg/blas.jl index 0ed249b91a9d1..6cf36f09b04e1 100644 --- a/base/linalg/blas.jl +++ b/base/linalg/blas.jl @@ -449,8 +449,8 @@ function axpy!(alpha::Number, x::Union{DenseArray{T},StridedVector{T}}, y::Union y end -function axpy!(alpha::Number, x::Array{T}, rx::Union{UnitRange{Ti},Range{Ti}}, - y::Array{T}, ry::Union{UnitRange{Ti},Range{Ti}}) where {T<:BlasFloat,Ti<:Integer} +function axpy!(alpha::Number, x::Array{T}, rx::Union{UnitRange{Ti},AbstractRange{Ti}}, + y::Array{T}, ry::Union{UnitRange{Ti},AbstractRange{Ti}}) where {T<:BlasFloat,Ti<:Integer} if length(rx) != length(ry) throw(DimensionMismatch("ranges of differing lengths")) end @@ -1515,8 +1515,8 @@ end end # module -function copy!(dest::Array{T}, rdest::Union{UnitRange{Ti},Range{Ti}}, - src::Array{T}, rsrc::Union{UnitRange{Ti},Range{Ti}}) where {T<:BlasFloat,Ti<:Integer} +function copy!(dest::Array{T}, rdest::Union{UnitRange{Ti},AbstractRange{Ti}}, + src::Array{T}, rsrc::Union{UnitRange{Ti},AbstractRange{Ti}}) where {T<:BlasFloat,Ti<:Integer} if minimum(rdest) < 1 || maximum(rdest) > length(dest) throw(ArgumentError("range out of bounds for dest, of length $(length(dest))")) end diff --git a/base/linalg/dense.jl b/base/linalg/dense.jl index d716fc08738b3..9c4741769c74a 100644 --- a/base/linalg/dense.jl +++ b/base/linalg/dense.jl @@ -115,7 +115,7 @@ isposdef(x::Number) = imag(x)==0 && real(x) > 0 stride1(x::Array) = 1 stride1(x::StridedVector) = stride(x, 1)::Int -function norm(x::StridedVector{T}, rx::Union{UnitRange{TI},Range{TI}}) where {T<:BlasFloat,TI<:Integer} +function norm(x::StridedVector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}) where {T<:BlasFloat,TI<:Integer} if minimum(rx) < 1 || maximum(rx) > length(x) throw(BoundsError(x, rx)) end @@ -240,7 +240,7 @@ end """ diagind(M, k::Integer=0) -A `Range` giving the indices of the `k`th diagonal of the matrix `M`. +An `AbstractRange` giving the indices of the `k`th diagonal of the matrix `M`. # Examples ```jldoctest diff --git a/base/linalg/matmul.jl b/base/linalg/matmul.jl index 7badc4be6176b..fe1b9b10194ab 100644 --- a/base/linalg/matmul.jl +++ b/base/linalg/matmul.jl @@ -41,7 +41,7 @@ end vecdot(x::Union{DenseArray{T},StridedVector{T}}, y::Union{DenseArray{T},StridedVector{T}}) where {T<:BlasReal} = BLAS.dot(x, y) vecdot(x::Union{DenseArray{T},StridedVector{T}}, y::Union{DenseArray{T},StridedVector{T}}) where {T<:BlasComplex} = BLAS.dotc(x, y) -function dot(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) where {T<:BlasReal,TI<:Integer} +function dot(x::Vector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},AbstractRange{TI}}) where {T<:BlasReal,TI<:Integer} if length(rx) != length(ry) throw(DimensionMismatch("length of rx, $(length(rx)), does not equal length of ry, $(length(ry))")) end @@ -54,7 +54,7 @@ function dot(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry: BLAS.dot(length(rx), pointer(x)+(first(rx)-1)*sizeof(T), step(rx), pointer(y)+(first(ry)-1)*sizeof(T), step(ry)) end -function dot(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) where {T<:BlasComplex,TI<:Integer} +function dot(x::Vector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},AbstractRange{TI}}) where {T<:BlasComplex,TI<:Integer} if length(rx) != length(ry) throw(DimensionMismatch("length of rx, $(length(rx)), does not equal length of ry, $(length(ry))")) end diff --git a/base/linalg/transpose.jl b/base/linalg/transpose.jl index 0baf0f9393f6e..a97fe96318ac8 100644 --- a/base/linalg/transpose.jl +++ b/base/linalg/transpose.jl @@ -128,8 +128,8 @@ end @inline adjoint(A::AbstractVector{<:Real}) = transpose(A) @inline adjoint(A::AbstractMatrix{<:Real}) = transpose(A) -function copy_transpose!(B::AbstractVecOrMat, ir_dest::Range{Int}, jr_dest::Range{Int}, - A::AbstractVecOrMat, ir_src::Range{Int}, jr_src::Range{Int}) +function copy_transpose!(B::AbstractVecOrMat, ir_dest::AbstractRange{Int}, jr_dest::AbstractRange{Int}, + A::AbstractVecOrMat, ir_src::AbstractRange{Int}, jr_src::AbstractRange{Int}) if length(ir_dest) != length(jr_src) throw(ArgumentError(string("source and destination must have same size (got ", length(jr_src)," and ",length(ir_dest),")"))) diff --git a/base/range.jl b/base/range.jl index ba90a98cbbb26..08a7eb941f276 100644 --- a/base/range.jl +++ b/base/range.jl @@ -77,11 +77,11 @@ range(a::AbstractFloat, st::Real, len::Integer) = range(a, float(st), len) ## 1-dimensional ranges ## -abstract type Range{T} <: AbstractArray{T,1} end +abstract type AbstractRange{T} <: AbstractArray{T,1} end ## ordinal ranges -abstract type OrdinalRange{T,S} <: Range{T} end +abstract type OrdinalRange{T,S} <: AbstractRange{T} end abstract type AbstractUnitRange{T} <: OrdinalRange{T,Int} end struct StepRange{T,S} <: OrdinalRange{T,S} @@ -190,7 +190,7 @@ value `r[1]`, but alternatively you can supply it as the value of with `TwicePrecision` this can be used to implement ranges that are free of roundoff error. """ -struct StepRangeLen{T,R,S} <: Range{T} +struct StepRangeLen{T,R,S} <: AbstractRange{T} ref::R # reference value (might be smallest-magnitude value in the range) step::S # step value len::Int # length of the range @@ -210,7 +210,7 @@ StepRangeLen{T}(ref::R, step::S, len::Integer, offset::Integer = 1) where {T,R,S ## linspace and logspace -struct LinSpace{T} <: Range{T} +struct LinSpace{T} <: AbstractRange{T} start::T stop::T len::Int @@ -273,7 +273,7 @@ parameters `pre` and `post` characters for each printed row, `sep` separator string between printed elements, `hdots` string for the horizontal ellipsis. """ -function print_range(io::IO, r::Range, +function print_range(io::IO, r::AbstractRange, pre::AbstractString = " ", sep::AbstractString = ",", post::AbstractString = "", @@ -344,7 +344,7 @@ logspace(start::Real, stop::Real, n::Integer=50; base=10) = base.^linspace(start ## interface implementations -size(r::Range) = (length(r),) +size(r::AbstractRange) = (length(r),) isempty(r::StepRange) = (r.start != r.stop) & ((r.step > zero(r.step)) != (r.stop > r.start)) @@ -355,7 +355,7 @@ isempty(r::LinSpace) = length(r) == 0 """ step(r) -Get the step size of a `Range` object. +Get the step size of an `AbstractRange` object. ```jldoctest julia> step(1:10) 1 @@ -376,9 +376,9 @@ step(r::StepRangeLen{T}) where {T} = T(r.step) step(r::LinSpace) = (last(r)-first(r))/r.lendiv step_hp(r::StepRangeLen) = r.step -step_hp(r::Range) = step(r) +step_hp(r::AbstractRange) = step(r) -unsafe_length(r::Range) = length(r) # generic fallback +unsafe_length(r::AbstractRange) = length(r) # generic fallback function unsafe_length(r::StepRange) n = Integer(div(r.stop+r.step - r.start, r.step)) @@ -438,11 +438,11 @@ last(r::LinSpace) = r.stop minimum(r::AbstractUnitRange) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : first(r) maximum(r::AbstractUnitRange) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : last(r) -minimum(r::Range) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : min(first(r), last(r)) -maximum(r::Range) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : max(first(r), last(r)) +minimum(r::AbstractRange) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : min(first(r), last(r)) +maximum(r::AbstractRange) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : max(first(r), last(r)) # Ranges are immutable -copy(r::Range) = r +copy(r::AbstractRange) = r ## iteration @@ -498,7 +498,7 @@ function getindex(v::OneTo{T}, i::Integer) where T convert(T, i) end -function getindex(v::Range{T}, i::Integer) where T +function getindex(v::AbstractRange{T}, i::Integer) where T @_inline_meta ret = convert(T, first(v) + (i - 1)*step_hp(v)) ok = ifelse(step(v) > zero(step(v)), @@ -535,7 +535,7 @@ function lerpi(j::Integer, d::Integer, a::T, b::T) where T T((1-t)*a + t*b) end -getindex(r::Range, ::Colon) = copy(r) +getindex(r::AbstractRange, ::Colon) = copy(r) function getindex(r::AbstractUnitRange, s::AbstractUnitRange{<:Integer}) @_inline_meta @@ -558,7 +558,7 @@ function getindex(r::AbstractUnitRange, s::StepRange{<:Integer}) range(st, step(s), length(s)) end -function getindex(r::StepRange, s::Range{<:Integer}) +function getindex(r::StepRange, s::AbstractRange{<:Integer}) @_inline_meta @boundscheck checkbounds(r, s) st = oftype(r.start, r.start + (first(s)-1)*step(r)) @@ -583,11 +583,11 @@ function getindex(r::LinSpace, s::OrdinalRange{<:Integer}) return LinSpace(vfirst, vlast, length(s)) end -show(io::IO, r::Range) = print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r))) +show(io::IO, r::AbstractRange) = print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r))) show(io::IO, r::UnitRange) = print(io, repr(first(r)), ':', repr(last(r))) show(io::IO, r::OneTo) = print(io, "Base.OneTo(", r.stop, ")") -==(r::T, s::T) where {T<:Range} = +==(r::T, s::T) where {T<:AbstractRange} = (first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s)) ==(r::OrdinalRange, s::OrdinalRange) = (first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s)) @@ -596,7 +596,7 @@ show(io::IO, r::OneTo) = print(io, "Base.OneTo(", r.stop, ")") ==(r::Union{StepRange{T},StepRangeLen{T,T}}, s::Union{StepRange{T},StepRangeLen{T,T}}) where {T} = (first(r) == first(s)) & (last(r) == last(s)) & (step(r) == step(s)) -function ==(r::Range, s::Range) +function ==(r::AbstractRange, s::AbstractRange) lr = length(r) if lr != length(s) return false @@ -669,11 +669,11 @@ function intersect(r::StepRange, s::StepRange) # if a == 0 # # One or both ranges have step 0. # if step1 == 0 && step2 == 0 - # return start1 == start2 ? r : Range(start1, 0, 0) + # return start1 == start2 ? r : AbstractRange(start1, 0, 0) # elseif step1 == 0 - # return start2 <= start1 <= stop2 && rem(start1 - start2, step2) == 0 ? r : Range(start1, 0, 0) + # return start2 <= start1 <= stop2 && rem(start1 - start2, step2) == 0 ? r : AbstractRange(start1, 0, 0) # else - # return start1 <= start2 <= stop1 && rem(start2 - start1, step1) == 0 ? (start2:step1:start2) : Range(start1, step1, 0) + # return start1 <= start2 <= stop1 && rem(start2 - start1, step1) == 0 ? (start2:step1:start2) : AbstractRange(start1, step1, 0) # end # end @@ -694,7 +694,7 @@ function intersect(r::StepRange, s::StepRange) m:a:n end -function intersect(r1::Range, r2::Range, r3::Range, r::Range...) +function intersect(r1::AbstractRange, r2::AbstractRange, r3::AbstractRange, r::AbstractRange...) i = intersect(intersect(r1, r2), r3) for t in r i = intersect(i, t) @@ -703,7 +703,7 @@ function intersect(r1::Range, r2::Range, r3::Range, r::Range...) end # findin (the index of intersection) -function _findin(r::Range{<:Integer}, span::AbstractUnitRange{<:Integer}) +function _findin(r::AbstractRange{<:Integer}, span::AbstractUnitRange{<:Integer}) local ifirst local ilast fspan = first(span) @@ -729,7 +729,7 @@ function findin(r::AbstractUnitRange{<:Integer}, span::AbstractUnitRange{<:Integ ifirst:ilast end -function findin(r::Range{<:Integer}, span::AbstractUnitRange{<:Integer}) +function findin(r::AbstractRange{<:Integer}, span::AbstractUnitRange{<:Integer}) ifirst, ilast = _findin(r, span) ifirst:1:ilast end @@ -744,7 +744,7 @@ end +(x::Real, r::AbstractUnitRange) = range(x + first(r), length(r)) # For #18336 we need to prevent promotion of the step type: +(x::Number, r::AbstractUnitRange) = range(x + first(r), step(r), length(r)) -+(x::Number, r::Range) = (x+first(r)):step(r):(x+last(r)) ++(x::Number, r::AbstractRange) = (x+first(r)):step(r):(x+last(r)) function +(x::Number, r::StepRangeLen{T}) where T newref = x + r.ref StepRangeLen{typeof(T(r.ref) + x)}(newref, r.step, length(r), r.offset) @@ -752,32 +752,32 @@ end function +(x::Number, r::LinSpace) LinSpace(x + r.start, x + r.stop, r.len) end -+(r::Range, x::Number) = x + r # assumes addition is commutative ++(r::AbstractRange, x::Number) = x + r # assumes addition is commutative --(x::Number, r::Range) = (x-first(r)):-step(r):(x-last(r)) +-(x::Number, r::AbstractRange) = (x-first(r)):-step(r):(x-last(r)) -(x::Number, r::StepRangeLen) = +(x, -r) function -(x::Number, r::LinSpace) LinSpace(x - r.start, x - r.stop, r.len) end --(r::Range, x::Number) = +(-x, r) +-(r::AbstractRange, x::Number) = +(-x, r) -*(x::Number, r::Range) = range(x*first(r), x*step(r), length(r)) +*(x::Number, r::AbstractRange) = range(x*first(r), x*step(r), length(r)) *(x::Number, r::StepRangeLen{T}) where {T} = StepRangeLen{typeof(x*T(r.ref))}(x*r.ref, x*r.step, length(r), r.offset) *(x::Number, r::LinSpace) = LinSpace(x * r.start, x * r.stop, r.len) # separate in case of noncommutative multiplication -*(r::Range, x::Number) = range(first(r)*x, step(r)*x, length(r)) +*(r::AbstractRange, x::Number) = range(first(r)*x, step(r)*x, length(r)) *(r::StepRangeLen{T}, x::Number) where {T} = StepRangeLen{typeof(T(r.ref)*x)}(r.ref*x, r.step*x, length(r), r.offset) *(r::LinSpace, x::Number) = LinSpace(r.start * x, r.stop * x, r.len) -/(r::Range, x::Number) = range(first(r)/x, step(r)/x, length(r)) +/(r::AbstractRange, x::Number) = range(first(r)/x, step(r)/x, length(r)) /(r::StepRangeLen{T}, x::Number) where {T} = StepRangeLen{typeof(T(r.ref)/x)}(r.ref/x, r.step/x, length(r), r.offset) /(r::LinSpace, x::Number) = LinSpace(r.start / x, r.stop / x, r.len) -/(x::Number, r::Range) = [ x/y for y=r ] +/(x::Number, r::AbstractRange) = [ x/y for y=r ] # promote eltype if at least one container wouldn't change, otherwise join container types. el_same(::Type{T}, a::Type{<:AbstractArray{T,n}}, b::Type{<:AbstractArray{T,n}}) where {T,n} = a @@ -813,11 +813,11 @@ convert(::Type{StepRange{T1,T2}}, r::StepRange{T1,T2}) where {T1,T2} = r promote_rule(a::Type{StepRange{T1a,T1b}}, ::Type{UR}) where {T1a,T1b,UR<:AbstractUnitRange} = promote_rule(a, StepRange{eltype(UR), eltype(UR)}) -convert(::Type{StepRange{T1,T2}}, r::Range) where {T1,T2} = +convert(::Type{StepRange{T1,T2}}, r::AbstractRange) where {T1,T2} = StepRange{T1,T2}(convert(T1, first(r)), convert(T2, step(r)), convert(T1, last(r))) convert(::Type{StepRange}, r::AbstractUnitRange{T}) where {T} = StepRange{T,T}(first(r), step(r), last(r)) -convert(::Type{StepRange{T1,T2} where T1}, r::Range) where {T2} = +convert(::Type{StepRange{T1,T2} where T1}, r::AbstractRange) where {T2} = convert(StepRange{eltype(r),T2}, r) promote_rule(::Type{StepRangeLen{T1,R1,S1}},::Type{StepRangeLen{T2,R2,S2}}) where {T1,T2,R1,R2,S1,S2} = @@ -830,20 +830,20 @@ convert(::Type{StepRangeLen{T,R,S}}, r::StepRangeLen) where {T,R,S} = convert(::Type{StepRangeLen{T}}, r::StepRangeLen) where {T} = StepRangeLen(convert(T, r.ref), convert(T, r.step), length(r), r.offset) -promote_rule(a::Type{StepRangeLen{T,R,S}}, ::Type{OR}) where {T,R,S,OR<:Range} = +promote_rule(a::Type{StepRangeLen{T,R,S}}, ::Type{OR}) where {T,R,S,OR<:AbstractRange} = promote_rule(a, StepRangeLen{eltype(OR), eltype(OR), eltype(OR)}) -convert(::Type{StepRangeLen{T,R,S}}, r::Range) where {T,R,S} = +convert(::Type{StepRangeLen{T,R,S}}, r::AbstractRange) where {T,R,S} = StepRangeLen{T,R,S}(R(first(r)), S(step(r)), length(r)) -convert(::Type{StepRangeLen{T}}, r::Range) where {T} = +convert(::Type{StepRangeLen{T}}, r::AbstractRange) where {T} = StepRangeLen(T(first(r)), T(step(r)), length(r)) -convert(::Type{StepRangeLen}, r::Range) = convert(StepRangeLen{eltype(r)}, r) +convert(::Type{StepRangeLen}, r::AbstractRange) = convert(StepRangeLen{eltype(r)}, r) promote_rule(a::Type{LinSpace{T1}}, b::Type{LinSpace{T2}}) where {T1,T2} = el_same(promote_type(T1,T2), a, b) convert(::Type{LinSpace{T}}, r::LinSpace{T}) where {T} = r -convert(::Type{LinSpace{T}}, r::Range) where {T} = +convert(::Type{LinSpace{T}}, r::AbstractRange) where {T} = LinSpace{T}(first(r), last(r), length(r)) -convert(::Type{LinSpace}, r::Range{T}) where {T} = +convert(::Type{LinSpace}, r::AbstractRange{T}) where {T} = convert(LinSpace{T}, r) promote_rule(a::Type{LinSpace{T}}, ::Type{OR}) where {T,OR<:OrdinalRange} = @@ -856,7 +856,7 @@ promote_rule(::Type{LinSpace{L}}, b::Type{StepRangeLen{T,R,S}}) where {L,T,R,S} ## concatenation ## -function vcat(rs::Range{T}...) where T +function vcat(rs::AbstractRange{T}...) where T n::Int = 0 for ra in rs n += length(ra) @@ -870,8 +870,8 @@ function vcat(rs::Range{T}...) where T return a end -convert(::Type{Array{T,1}}, r::Range{T}) where {T} = vcat(r) -collect(r::Range) = vcat(r) +convert(::Type{Array{T,1}}, r::AbstractRange{T}) where {T} = vcat(r) +collect(r::AbstractRange) = vcat(r) reverse(r::OrdinalRange) = colon(last(r), -step(r), first(r)) reverse(r::StepRangeLen) = StepRangeLen(r.ref, -r.step, length(r), length(r)-r.offset+1) @@ -880,31 +880,31 @@ reverse(r::LinSpace) = LinSpace(r.stop, r.start, length(r)) ## sorting ## issorted(r::AbstractUnitRange) = true -issorted(r::Range) = length(r) <= 1 || step(r) >= zero(step(r)) +issorted(r::AbstractRange) = length(r) <= 1 || step(r) >= zero(step(r)) sort(r::AbstractUnitRange) = r sort!(r::AbstractUnitRange) = r -sort(r::Range) = issorted(r) ? r : reverse(r) +sort(r::AbstractRange) = issorted(r) ? r : reverse(r) sortperm(r::AbstractUnitRange) = 1:length(r) -sortperm(r::Range) = issorted(r) ? (1:1:length(r)) : (length(r):-1:1) +sortperm(r::AbstractRange) = issorted(r) ? (1:1:length(r)) : (length(r):-1:1) -function sum(r::Range{<:Real}) +function sum(r::AbstractRange{<:Real}) l = length(r) # note that a little care is required to avoid overflow in l*(l-1)/2 return l * first(r) + (iseven(l) ? (step(r) * (l-1)) * (l>>1) : (step(r) * l) * ((l-1)>>1)) end -function mean(r::Range{<:Real}) +function mean(r::AbstractRange{<:Real}) isempty(r) && throw(ArgumentError("mean of an empty range is undefined")) (first(r) + last(r)) / 2 end -median(r::Range{<:Real}) = mean(r) +median(r::AbstractRange{<:Real}) = mean(r) -function _in_range(x, r::Range) +function _in_range(x, r::AbstractRange) if step(r) == 0 return !isempty(r) && first(r) == x else @@ -912,17 +912,17 @@ function _in_range(x, r::Range) return n >= 1 && n <= length(r) && r[n] == x end end -in(x::Real, r::Range{<:Real}) = _in_range(x, r) +in(x::Real, r::AbstractRange{<:Real}) = _in_range(x, r) # This method needs to be defined separately since -(::T, ::T) can be implemented # even if -(::T, ::Real) is not -in(x::T, r::Range{T}) where {T} = _in_range(x, r) +in(x::T, r::AbstractRange{T}) where {T} = _in_range(x, r) in(x::Integer, r::AbstractUnitRange{<:Integer}) = (first(r) <= x) & (x <= last(r)) -in(x::Real, r::Range{T}) where {T<:Integer} = +in(x::Real, r::AbstractRange{T}) where {T<:Integer} = isinteger(x) && !isempty(r) && x >= minimum(r) && x <= maximum(r) && (mod(convert(T,x),step(r))-mod(first(r),step(r)) == 0) -in(x::Char, r::Range{Char}) = +in(x::Char, r::AbstractRange{Char}) = !isempty(r) && x >= minimum(r) && x <= maximum(r) && (mod(Int(x) - Int(first(r)), step(r)) == 0) diff --git a/base/reduce.jl b/base/reduce.jl index 626809a73721a..6b0415fbe266d 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -472,7 +472,7 @@ minimum(a) = mapreduce(identity, scalarmin, a) ## extrema -extrema(r::Range) = (minimum(r), maximum(r)) +extrema(r::AbstractRange) = (minimum(r), maximum(r)) extrema(x::Real) = (x, x) """ diff --git a/base/replutil.jl b/base/replutil.jl index 2e2031b506e3e..a59905d86af45 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -137,7 +137,7 @@ function show(io::IO, ::MIME"text/plain", t::Task) end show(io::IO, ::MIME"text/plain", X::AbstractArray) = showarray(io, X, false) -show(io::IO, ::MIME"text/plain", r::Range) = show(io, r) # always use the compact form for printing ranges +show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges # display something useful even for strings containing arbitrary # (non-UTF8) binary data: @@ -186,7 +186,7 @@ function showerror(io::IO, ex::BoundsError) if isdefined(ex, :i) !isa(ex.a, AbstractArray) && print(io, "\n ") print(io, " at index [") - if isa(ex.i, Range) + if isa(ex.i, AbstractRange) print(io, ex.i) else join(io, ex.i, ", ") diff --git a/base/reshapedarray.jl b/base/reshapedarray.jl index 1c63d5b5349c2..fef634061165b 100644 --- a/base/reshapedarray.jl +++ b/base/reshapedarray.jl @@ -232,7 +232,7 @@ end end # helpful error message for a common failure case -const ReshapedRange{T,N,A<:Range} = ReshapedArray{T,N,A,Tuple{}} +const ReshapedRange{T,N,A<:AbstractRange} = ReshapedArray{T,N,A,Tuple{}} setindex!(A::ReshapedRange, val, index::Int) = _rs_setindex!_err() setindex!(A::ReshapedRange{T,N}, val, indexes::Vararg{Int,N}) where {T,N} = _rs_setindex!_err() setindex!(A::ReshapedRange, val, index::ReshapedIndex) = _rs_setindex!_err() diff --git a/base/set.jl b/base/set.jl index 86f1e93b889b4..916d9746a1435 100644 --- a/base/set.jl +++ b/base/set.jl @@ -446,7 +446,7 @@ end allunique(::Set) = true -allunique(r::Range{T}) where {T} = (step(r) != zero(T)) || (length(r) <= 1) +allunique(r::AbstractRange{T}) where {T} = (step(r) != zero(T)) || (length(r) <= 1) function filter(f, s::Set) u = similar(s) diff --git a/base/sort.jl b/base/sort.jl index cb28e79d7de52..d965217814487 100644 --- a/base/sort.jl +++ b/base/sort.jl @@ -214,7 +214,7 @@ function searchsorted(v::AbstractVector, x, ilo::Int, ihi::Int, o::Ordering) return (lo + 1) : (hi - 1) end -function searchsortedlast(a::Range{<:Real}, x::Real, o::DirectOrdering) +function searchsortedlast(a::AbstractRange{<:Real}, x::Real, o::DirectOrdering) if step(a) == 0 lt(o, x, first(a)) ? 0 : length(a) else @@ -223,7 +223,7 @@ function searchsortedlast(a::Range{<:Real}, x::Real, o::DirectOrdering) end end -function searchsortedfirst(a::Range{<:Real}, x::Real, o::DirectOrdering) +function searchsortedfirst(a::AbstractRange{<:Real}, x::Real, o::DirectOrdering) if step(a) == 0 lt(o, first(a), x) ? length(a) + 1 : 1 else @@ -232,7 +232,7 @@ function searchsortedfirst(a::Range{<:Real}, x::Real, o::DirectOrdering) end end -function searchsortedlast(a::Range{<:Integer}, x::Real, o::DirectOrdering) +function searchsortedlast(a::AbstractRange{<:Integer}, x::Real, o::DirectOrdering) if step(a) == 0 lt(o, x, first(a)) ? 0 : length(a) else @@ -240,7 +240,7 @@ function searchsortedlast(a::Range{<:Integer}, x::Real, o::DirectOrdering) end end -function searchsortedfirst(a::Range{<:Integer}, x::Real, o::DirectOrdering) +function searchsortedfirst(a::AbstractRange{<:Integer}, x::Real, o::DirectOrdering) if step(a) == 0 lt(o, first(a), x) ? length(a)+1 : 1 else @@ -248,7 +248,7 @@ function searchsortedfirst(a::Range{<:Integer}, x::Real, o::DirectOrdering) end end -function searchsortedfirst(a::Range{<:Integer}, x::Unsigned, o::DirectOrdering) +function searchsortedfirst(a::AbstractRange{<:Integer}, x::Unsigned, o::DirectOrdering) if lt(o, first(a), x) if step(a) == 0 length(a) + 1 @@ -260,7 +260,7 @@ function searchsortedfirst(a::Range{<:Integer}, x::Unsigned, o::DirectOrdering) end end -function searchsortedlast(a::Range{<:Integer}, x::Unsigned, o::DirectOrdering) +function searchsortedlast(a::AbstractRange{<:Integer}, x::Unsigned, o::DirectOrdering) if lt(o, x, first(a)) 0 elseif step(a) == 0 @@ -270,7 +270,7 @@ function searchsortedlast(a::Range{<:Integer}, x::Unsigned, o::DirectOrdering) end end -searchsorted(a::Range{<:Real}, x::Real, o::DirectOrdering) = +searchsorted(a::AbstractRange{<:Real}, x::Real, o::DirectOrdering) = searchsortedfirst(a, x, o) : searchsortedlast(a, x, o) for s in [:searchsortedfirst, :searchsortedlast, :searchsorted] diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index 5d27cc316c31e..15daf86f9a0ca 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -1921,7 +1921,7 @@ indmin(A::SparseMatrixCSC) = findmin(A)[2] indmax(A::SparseMatrixCSC) = findmax(A)[2] ## getindex -function rangesearch(haystack::Range, needle) +function rangesearch(haystack::AbstractRange, needle) (i,rem) = divrem(needle - first(haystack), step(haystack)) (rem==0 && 1<=i+1<=length(haystack)) ? i+1 : 0 end @@ -1978,7 +1978,7 @@ end getindex_traverse_col(::AbstractUnitRange, lo::Int, hi::Int) = lo:hi getindex_traverse_col(I::StepRange, lo::Int, hi::Int) = step(I) > 0 ? (lo:1:hi) : (hi:-1:lo) -function getindex(A::SparseMatrixCSC{Tv,Ti}, I::Range, J::AbstractVector) where {Tv,Ti<:Integer} +function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractRange, J::AbstractVector) where {Tv,Ti<:Integer} # Ranges for indexing rows (m, n) = size(A) # whole columns: @@ -2338,10 +2338,10 @@ function getindex(A::SparseMatrixCSC{Tv}, I::AbstractArray) where Tv end # logical getindex -getindex(A::SparseMatrixCSC{<:Any,<:Integer}, I::Range{Bool}, J::AbstractVector{Bool}) = error("Cannot index with Range{Bool}") -getindex(A::SparseMatrixCSC{<:Any,<:Integer}, I::Range{Bool}, J::AbstractVector{<:Integer}) = error("Cannot index with Range{Bool}") +getindex(A::SparseMatrixCSC{<:Any,<:Integer}, I::AbstractRange{Bool}, J::AbstractVector{Bool}) = error("Cannot index with AbstractRange{Bool}") +getindex(A::SparseMatrixCSC{<:Any,<:Integer}, I::AbstractRange{Bool}, J::AbstractVector{<:Integer}) = error("Cannot index with AbstractRange{Bool}") -getindex(A::SparseMatrixCSC, I::Range{<:Integer}, J::AbstractVector{Bool}) = A[I,find(J)] +getindex(A::SparseMatrixCSC, I::AbstractRange{<:Integer}, J::AbstractVector{Bool}) = A[I,find(J)] getindex(A::SparseMatrixCSC, I::Integer, J::AbstractVector{Bool}) = A[I,find(J)] getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::Integer) = A[find(I),J] getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = A[find(I),find(J)] diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index 630fea82a0a12..acaac624548ea 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -573,7 +573,7 @@ function _logical_index(A::SparseMatrixCSC{Tv}, I::AbstractArray{Bool}) where Tv SparseVector(n, rowvalB, nzvalB) end -# TODO: further optimizations are available for ::Colon and other types of Range +# TODO: further optimizations are available for ::Colon and other types of AbstractRange getindex(A::SparseMatrixCSC, ::Colon) = A[1:end] function getindex(A::SparseMatrixCSC{Tv}, I::AbstractUnitRange) where Tv diff --git a/base/statistics.jl b/base/statistics.jl index 226a8661a85f1..5094e43762ad0 100644 --- a/base/statistics.jl +++ b/base/statistics.jl @@ -224,7 +224,7 @@ varm(iterable, m::Number; corrected::Bool=true) = ## variances over ranges -function varm(v::Range, m::Number) +function varm(v::AbstractRange, m::Number) f = first(v) - m s = step(v) l = length(v) @@ -235,7 +235,7 @@ function varm(v::Range, m::Number) return vv end -function var(v::Range) +function var(v::AbstractRange) s = step(v) l = length(v) vv = abs2(s) * (l + 1) * l / 12 @@ -561,7 +561,7 @@ julia> middle(1:10) 5.5 ``` """ -middle(a::Range) = middle(a[1], a[end]) +middle(a::AbstractRange) = middle(a[1], a[end]) """ middle(a) diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 5fd209255eb0c..e7cea9e8da9c4 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -239,7 +239,7 @@ function nextind(s::AbstractString, i::Integer) end checkbounds(s::AbstractString, i::Integer) = start(s) <= i <= endof(s) || throw(BoundsError(s, i)) -checkbounds(s::AbstractString, r::Range{<:Integer}) = isempty(r) || (minimum(r) >= start(s) && maximum(r) <= endof(s)) || throw(BoundsError(s, r)) +checkbounds(s::AbstractString, r::AbstractRange{<:Integer}) = isempty(r) || (minimum(r) >= start(s) && maximum(r) <= endof(s)) || throw(BoundsError(s, r)) # The following will end up using a deprecated checkbounds, when the covariant parameter is not Integer checkbounds(s::AbstractString, I::AbstractArray{<:Real}) = all(i -> checkbounds(s, i), I) checkbounds(s::AbstractString, I::AbstractArray{<:Integer}) = all(i -> checkbounds(s, i), I) diff --git a/base/subarray.jl b/base/subarray.jl index 5db883f964c06..4929635729dc0 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -46,7 +46,7 @@ viewindexing(I::Tuple{Slice, Slice, Vararg{Any}}) = (@_inline_meta; viewindexing # A UnitRange can follow Slices, but only if all other indices are scalar viewindexing(I::Tuple{Slice, UnitRange, Vararg{ScalarIndex}}) = IndexLinear() # In general, ranges are only fast if all other indices are scalar -viewindexing(I::Tuple{Union{Range, Slice}, Vararg{ScalarIndex}}) = IndexLinear() +viewindexing(I::Tuple{Union{AbstractRange, Slice}, Vararg{ScalarIndex}}) = IndexLinear() # All other index combinations are slow viewindexing(I::Tuple{Vararg{Any}}) = IndexCartesian() # Of course, all other array types are slow @@ -257,7 +257,7 @@ substrides(parent, I::Tuple) = substrides(1, parent, 1, I) substrides(s, parent, dim, ::Tuple{}) = () substrides(s, parent, dim, I::Tuple{ScalarIndex, Vararg{Any}}) = (substrides(s*size(parent, dim), parent, dim+1, tail(I))...) substrides(s, parent, dim, I::Tuple{Slice, Vararg{Any}}) = (s, substrides(s*size(parent, dim), parent, dim+1, tail(I))...) -substrides(s, parent, dim, I::Tuple{Range, Vararg{Any}}) = (s*step(I[1]), substrides(s*size(parent, dim), parent, dim+1, tail(I))...) +substrides(s, parent, dim, I::Tuple{AbstractRange, Vararg{Any}}) = (s*step(I[1]), substrides(s*size(parent, dim), parent, dim+1, tail(I))...) substrides(s, parent, dim, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError("strides is invalid for SubArrays with indices of type $(typeof(I[1]))")) stride(V::SubArray, d::Integer) = d <= ndims(V) ? strides(V)[d] : strides(V)[end] * size(V)[end] @@ -267,7 +267,7 @@ compute_stride1(parent::AbstractArray, I::NTuple{N,Any}) where {N} = compute_stride1(s, inds, I::Tuple{}) = s compute_stride1(s, inds, I::Tuple{ScalarIndex, Vararg{Any}}) = (@_inline_meta; compute_stride1(s*unsafe_length(inds[1]), tail(inds), tail(I))) -compute_stride1(s, inds, I::Tuple{Range, Vararg{Any}}) = s*step(I[1]) +compute_stride1(s, inds, I::Tuple{AbstractRange, Vararg{Any}}) = s*step(I[1]) compute_stride1(s, inds, I::Tuple{Slice, Vararg{Any}}) = s compute_stride1(s, inds, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError("invalid strided index type $(typeof(I[1]))")) @@ -358,7 +358,7 @@ function parentdims(s::SubArray) j = 1 for i = 1:ndims(s.parent) r = s.indexes[i] - if j <= nd && (isa(r,Union{Slice,Range}) ? sp[i]*step(r) : sp[i]) == sv[j] + if j <= nd && (isa(r,Union{Slice,AbstractRange}) ? sp[i]*step(r) : sp[i]) == sv[j] dimindex[j] = i j += 1 end diff --git a/base/twiceprecision.jl b/base/twiceprecision.jl index a4e8f055377e5..0e9a32f12a9ff 100644 --- a/base/twiceprecision.jl +++ b/base/twiceprecision.jl @@ -485,20 +485,20 @@ convert(::Type{StepRangeLen{Float64}}, r::StepRangeLen) = convert(::Type{StepRangeLen{T}}, r::StepRangeLen) where {T<:IEEEFloat} = _convertSRL(StepRangeLen{T,Float64,Float64}, r) -convert(::Type{StepRangeLen{Float64}}, r::Range) = +convert(::Type{StepRangeLen{Float64}}, r::AbstractRange) = _convertSRL(StepRangeLen{Float64,TwicePrecision{Float64},TwicePrecision{Float64}}, r) -convert(::Type{StepRangeLen{T}}, r::Range) where {T<:IEEEFloat} = +convert(::Type{StepRangeLen{T}}, r::AbstractRange) where {T<:IEEEFloat} = _convertSRL(StepRangeLen{T,Float64,Float64}, r) function _convertSRL(::Type{StepRangeLen{T,R,S}}, r::StepRangeLen{<:Integer}) where {T,R,S} StepRangeLen{T,R,S}(R(r.ref), S(r.step), length(r), r.offset) end -function _convertSRL(::Type{StepRangeLen{T,R,S}}, r::Range{<:Integer}) where {T,R,S} +function _convertSRL(::Type{StepRangeLen{T,R,S}}, r::AbstractRange{<:Integer}) where {T,R,S} StepRangeLen{T,R,S}(R(first(r)), S(step(r)), length(r)) end -function _convertSRL(::Type{StepRangeLen{T,R,S}}, r::Range{U}) where {T,R,S,U} +function _convertSRL(::Type{StepRangeLen{T,R,S}}, r::AbstractRange{U}) where {T,R,S,U} # if start and step have a rational approximation in the old type, # then we transfer that rational approximation to the new type f, s = first(r), step(r) @@ -521,7 +521,7 @@ end function __convertSRL(::Type{StepRangeLen{T,R,S}}, r::StepRangeLen{U}) where {T,R,S,U} StepRangeLen{T,R,S}(R(r.ref), S(r.step), length(r), r.offset) end -function __convertSRL(::Type{StepRangeLen{T,R,S}}, r::Range{U}) where {T,R,S,U} +function __convertSRL(::Type{StepRangeLen{T,R,S}}, r::AbstractRange{U}) where {T,R,S,U} StepRangeLen{T,R,S}(R(first(r)), S(step(r)), length(r)) end diff --git a/contrib/Julia_Notepad++.xml b/contrib/Julia_Notepad++.xml index 2d548197bd9de..e43a1ab4865ee 100644 --- a/contrib/Julia_Notepad++.xml +++ b/contrib/Julia_Notepad++.xml @@ -25,7 +25,7 @@ true false C_NULL Inf NaN Inf32 NaN32 nothing - AbstractArray AbstractMatrix AbstractRemoteRef AbstractSparseMatrix AbstractString AbstractVector Any ArgumentError Array Associative BigFloat BigInt BitArray BitMatrix BitVector Bool BunchKaufman Cchar Cdouble Cfloat Char CharString CholeskyDense CholeskyPivotedDense Cint Cintmax_t Clong Clonglong Colon Complex Complex128 Complex64 ComplexPair Cptrdiff_t Cshort Csize_t Cuchar Cuint Cuintmax_t Culong Culonglong Cushort DArray Dict Dims DisconnectException EOFError EachLine EnvHash ErrorException Exception Expr Factorization Filter Float Float32 Float64 Function GSVDDense IO IOBuffer IOStream ImaginaryUnit InsertionSort Int Int128 Int16 Int32 Int64 Int8 IntSet Integer KeyError LDLTTridiagonal LUDense LUTridiagonal LoadError LocalProcess Matrix MergeSort MethodError NTuple Number ObjectIdDict ObjectIdDict OrdinalRange ParseError PipeBuffer ProcessGroup Ptr QRDense QRPivotedDense QuickSort Range Range1 RangeIndex Ranges Rational Real Regex RegexMatch RegexMatchIterator RepString RevString Reverse SVDDense Set Signed SparseMatrixCSC SpawnNullStream Stat StridedArray StridedMatrix StridedVecOrMat StridedVector String SubArray SubDArray SubOrDArray SubString SymTridiagonal Symbol SystemError Task TCPSocket TimSort Tridiagonal Tuple Type TypeError UInt UInt128 UInt16 UInt32 UInt64 UInt8 UVError Union Unsigned VecOrMat Vector VersionNumber Void WeakKeyDict WeakRef Zip + AbstractArray AbstractMatrix AbstractRange AbstractRemoteRef AbstractSparseMatrix AbstractString AbstractVector Any ArgumentError Array Associative BigFloat BigInt BitArray BitMatrix BitVector Bool BunchKaufman Cchar Cdouble Cfloat Char CharString CholeskyDense CholeskyPivotedDense Cint Cintmax_t Clong Clonglong Colon Complex Complex128 Complex64 ComplexPair Cptrdiff_t Cshort Csize_t Cuchar Cuint Cuintmax_t Culong Culonglong Cushort DArray Dict Dims DisconnectException EOFError EachLine EnvHash ErrorException Exception Expr Factorization Filter Float Float32 Float64 Function GSVDDense IO IOBuffer IOStream ImaginaryUnit InsertionSort Int Int128 Int16 Int32 Int64 Int8 IntSet Integer KeyError LDLTTridiagonal LUDense LUTridiagonal LoadError LocalProcess Matrix MergeSort MethodError NTuple Number ObjectIdDict ObjectIdDict OrdinalRange ParseError PipeBuffer ProcessGroup Ptr QRDense QRPivotedDense QuickSort RangeIndex Rational Real Regex RegexMatch RegexMatchIterator RepString RevString Reverse SVDDense Set Signed SparseMatrixCSC SpawnNullStream Stat StridedArray StridedMatrix StridedVecOrMat StridedVector String SubArray SubDArray SubOrDArray SubString SymTridiagonal Symbol SystemError Task TCPSocket TimSort Tridiagonal Tuple Type TypeError UInt UInt128 UInt16 UInt32 UInt64 UInt8 UVError Union UnitRange Unsigned VecOrMat Vector VersionNumber Void WeakKeyDict WeakRef Zip abstract begin baremodule primitive break catch ccall const continue do else elseif end export finally for function global if struct import importall let local macro module quote return try mutable typealias using while close enumerate error info open print println read write warn print println diff --git a/contrib/julia.hrc b/contrib/julia.hrc index 5162fc0447b13..b175639b84f3e 100644 --- a/contrib/julia.hrc +++ b/contrib/julia.hrc @@ -146,8 +146,8 @@ - - + + diff --git a/contrib/julia.lang b/contrib/julia.lang index 566685a1ebb3a..30705ae7eb3d4 100644 --- a/contrib/julia.lang +++ b/contrib/julia.lang @@ -231,7 +231,7 @@ Any|Void Type(Constructor|Name|Var|_Array)?|(Union|Data|NonTuple)Type (Abstract|Strided|Bit)?(Array|Matrix|Vector) - Abstract(Cmd|RNG|SparseMatrix) + Abstract(Cmd|Range|RNG|SparseMatrix) (Abstract|Strided)?VecOrMat SparseMatrixCSC (D|Sub((Or)?D)?)Array @@ -301,7 +301,7 @@ Process(Chain(OrNot)?|Group)? Ptr QR(Pivoted)? - Range(s|1|Index|VecIntList)? + Range(Index|VecIntList)? RawOrBoxedHandle Redirectable Regex(Match(Iterator)?)? @@ -325,6 +325,7 @@ UV(Handle|PollingWatcher|Stream) UDPSocket Undef(RefTag)? + UnitRange VarTable Vararg VersionNumber diff --git a/contrib/julia.xml b/contrib/julia.xml index 65ebbc95ee351..a0bb9c33b7984 100644 --- a/contrib/julia.xml +++ b/contrib/julia.xml @@ -77,6 +77,7 @@ AbstractArray AbstractMatrix + AbstractRange AbstractRemoteRef AbstractSparseMatrix AbstractVector @@ -148,10 +149,7 @@ PipeBuffer ProcessGroup Ptr - Range - Range1 RangeIndex - Ranges Rational Real Regex @@ -193,6 +191,7 @@ UInt64 UInt128 Union + UnitRange Unsigned UVError VecOrMat diff --git a/doc/src/manual/arrays.md b/doc/src/manual/arrays.md index e9b5d50d8580d..c7691100cc1cc 100644 --- a/doc/src/manual/arrays.md +++ b/doc/src/manual/arrays.md @@ -348,7 +348,7 @@ indices and can be converted to such by [`to_indices`](@ref): 2. An array of scalar indices. This includes: * Vectors and multidimensional arrays of integers * Empty arrays like `[]`, which select no elements - * `Range`s of the form `a:c` or `a:b:c`, which select contiguous or strided subsections from `a` to `c` (inclusive) + * Ranges like `a:c` or `a:b:c`, which select contiguous or strided subsections from `a` to `c` (inclusive) * Any custom array of scalar indices that is a subtype of `AbstractArray` * Arrays of `CartesianIndex{N}` (see below for more details) 3. An object that represents an array of scalar indices and can be converted to such by [`to_indices`](@ref). By default this includes: diff --git a/doc/src/manual/control-flow.md b/doc/src/manual/control-flow.md index 37f44ee167343..a48b619d237a6 100644 --- a/doc/src/manual/control-flow.md +++ b/doc/src/manual/control-flow.md @@ -409,7 +409,7 @@ julia> for i = 1:5 5 ``` -Here the `1:5` is a `Range` object, representing the sequence of numbers 1, 2, 3, 4, 5. The `for` +Here the `1:5` is a range object, representing the sequence of numbers 1, 2, 3, 4, 5. The `for` loop iterates through these values, assigning each one in turn to the variable `i`. One rather important distinction between the previous `while` loop form and the `for` loop form is the scope during which the variable is visible. If the variable `i` has not been introduced in an other diff --git a/doc/src/manual/interfaces.md b/doc/src/manual/interfaces.md index f321efb204aac..8576bffa4d9b7 100644 --- a/doc/src/manual/interfaces.md +++ b/doc/src/manual/interfaces.md @@ -327,8 +327,8 @@ julia> A[:] = 1:length(A); A ``` The result of indexing an `AbstractArray` can itself be an array (for instance when indexing by -a `Range`). The `AbstractArray` fallback methods use [`similar`](@ref) to allocate an `Array` of the -appropriate size and element type, which is filled in using the basic indexing method described +an `AbstractRange`). The `AbstractArray` fallback methods use [`similar`](@ref) to allocate an `Array` +of the appropriate size and element type, which is filled in using the basic indexing method described above. However, when implementing an array wrapper you often want the result to be wrapped as well: diff --git a/doc/src/manual/noteworthy-differences.md b/doc/src/manual/noteworthy-differences.md index 202dbf12224cd..65bc7e37e76ae 100644 --- a/doc/src/manual/noteworthy-differences.md +++ b/doc/src/manual/noteworthy-differences.md @@ -34,8 +34,8 @@ may trip up Julia users accustomed to MATLAB: with spaces (`[x y z]`). - To construct block matrices (concatenating in the first two dimensions), use either [`hvcat`](@ref) or combine spaces and semicolons (`[a b; c d]`). - * In Julia, `a:b` and `a:b:c` construct `Range` objects. To construct a full vector like in MATLAB, - use [`collect(a:b)`](@ref). Generally, there is no need to call `collect` though. `Range` will + * In Julia, `a:b` and `a:b:c` construct `AbstractRange` objects. To construct a full vector like in MATLAB, + use [`collect(a:b)`](@ref). Generally, there is no need to call `collect` though. An `AbstractRange` object will act like a normal array in most cases but is more efficient because it lazily computes its values. This pattern of creating specialized objects instead of full arrays is used frequently, and is also seen in functions such as [`linspace`](@ref), or with iterators such as `enumerate`, and @@ -156,8 +156,8 @@ For users coming to Julia from R, these are some noteworthy differences: on large data structures much more efficiently. * In Julia, vectors and matrices are concatenated using [`hcat`](@ref), [`vcat`](@ref) and [`hvcat`](@ref), not `c`, `rbind` and `cbind` like in R. - * In Julia, a range like `a:b` is not shorthand for a vector like in R, but is a specialized `Range` - that is used for iteration without high memory overhead. To convert a range into a vector, use + * In Julia, a range like `a:b` is not shorthand for a vector like in R, but is a specialized `AbstractRange` + object that is used for iteration without high memory overhead. To convert a range into a vector, use [`collect(a:b)`](@ref). * Julia's [`max`](@ref) and [`min`](@ref) are the equivalent of `pmax` and `pmin` respectively in R, but both arguments need to have the same dimensions. While [`maximum`](@ref) and [`minimum`](@ref) diff --git a/doc/src/stdlib/collections.md b/doc/src/stdlib/collections.md index e83303f7ab89a..5c5ecc11ca317 100644 --- a/doc/src/stdlib/collections.md +++ b/doc/src/stdlib/collections.md @@ -35,7 +35,7 @@ Base.iteratoreltype Fully implemented by: - * `Range` + * `AbstractRange` * `UnitRange` * `Tuple` * `Number` @@ -58,7 +58,7 @@ Base.length Fully implemented by: - * `Range` + * `AbstractRange` * `UnitRange` * `Tuple` * `Number` @@ -151,7 +151,7 @@ Fully implemented by: Partially implemented by: - * `Range` + * `AbstractRange` * `UnitRange` * `Tuple` * `AbstractString` diff --git a/test/TestHelpers.jl b/test/TestHelpers.jl index 84f8edc7fc7cb..6a2761997cb27 100644 --- a/test/TestHelpers.jl +++ b/test/TestHelpers.jl @@ -221,7 +221,7 @@ offset(offsets::NTuple{N,Int}, inds::NTuple{N,Int}) where {N} = _offset((), offs _offset(out, ::Tuple{}, ::Tuple{}) = out @inline _offset(out, offsets, inds) = _offset((out..., inds[1]-offsets[1]), Base.tail(offsets), Base.tail(inds)) -indsoffset(r::Range) = first(r) - 1 +indsoffset(r::AbstractRange) = first(r) - 1 indsoffset(i::Integer) = 0 Base.resize!(A::OffsetVector, nl::Integer) = (resize!(A.parent, nl); A) diff --git a/test/core.jl b/test/core.jl index 9c5d8e37da9d6..822be8dae02d4 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1737,7 +1737,7 @@ mutable struct A6142 <: AbstractMatrix{Float64}; end +(x::A6142, y::UniformScaling{TJ}) where {TJ} = "UniformScaling method called" +(x::A6142, y::AbstractArray) = "AbstractArray method called" @test A6142() + I == "UniformScaling method called" -+(x::A6142, y::Range) = "Range method called" #16324 ambiguity ++(x::A6142, y::AbstractRange) = "AbstractRange method called" #16324 ambiguity # issue #6175 function g6175(); print(""); (); end @@ -1850,7 +1850,7 @@ end # issue #6387 primitive type Date6387{C} 64 end -mutable struct DateRange6387{C} <: Range{Date6387{C}} +mutable struct DateRange6387{C} <: AbstractRange{Date6387{C}} end mutable struct ObjMember @@ -1859,7 +1859,7 @@ end obj6387 = ObjMember(DateRange6387{Int64}()) -function v6387(r::Range{T}) where T +function v6387(r::AbstractRange{T}) where T a = Array{T}(1) a[1] = Core.Intrinsics.bitcast(Date6387{Int64}, Int64(1)) return a diff --git a/test/ranges.jl b/test/ranges.jl index a318f04b2c0f0..b9e1696f7590b 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -294,7 +294,7 @@ end @test intersect(-51:5:100, -33:7:125) == -26:35:79 @test intersect(-51:5:100, -32:7:125) == -11:35:94 #@test intersect(0:6:24, 6+0*(0:4:24)) == 6:6:6 -#@test intersect(12+0*(0:6:24), 0:4:24) == Range(12, 0, 5) +#@test intersect(12+0*(0:6:24), 0:4:24) == AbstractRange(12, 0, 5) #@test isempty(intersect(6+0*(0:6:24), 0:4:24)) @test intersect(-10:3:24, -10:3:24) == -10:3:23 @test isempty(intersect(-11:3:24, -10:3:24)) @@ -372,7 +372,7 @@ r = (-4*Int64(maxintfloat(Int === Int32 ? Float32 : Float64))):5 @test_throws BoundsError (0:2:10)[7:7] # indexing with negative ranges (#8351) -for a=Range[3:6, 0:2:10], b=Range[0:1, 2:-1:0] +for a=AbstractRange[3:6, 0:2:10], b=AbstractRange[0:1, 2:-1:0] @test_throws BoundsError a[b] end @@ -649,9 +649,9 @@ r = LinSpace(1,4,4) # comparing and hashing ranges let - Rs = Range[1:2, map(Int32,1:3:17), map(Int64,1:3:17), 1:0, 17:-3:0, - 0.0:0.1:1.0, map(Float32,0.0:0.1:1.0), - linspace(0, 1, 20), map(Float32, linspace(0, 1, 20))] + Rs = AbstractRange[1:2, map(Int32,1:3:17), map(Int64,1:3:17), 1:0, 17:-3:0, + 0.0:0.1:1.0, map(Float32,0.0:0.1:1.0), + linspace(0, 1, 20), map(Float32, linspace(0, 1, 20))] for r in Rs local r ar = collect(r) @@ -713,7 +713,7 @@ end # issue #7114 r = -0.004532318104333742:1.2597349521122731e-5:0.008065031416788989 @test length(r[1:end-1]) == length(r) - 1 -@test isa(r[1:2:end],Range) && length(r[1:2:end]) == div(length(r)+1, 2) +@test isa(r[1:2:end],AbstractRange) && length(r[1:2:end]) == div(length(r)+1, 2) @test r[3:5][2] ≈ r[4] @test r[5:-2:1][2] ≈ r[3] @test_throws BoundsError r[0:10] @@ -896,7 +896,7 @@ test_range_index(linspace(1.0, 1.0, 1), 1:1) test_range_index(linspace(1.0, 1.0, 1), 1:0) test_range_index(linspace(1.0, 2.0, 0), 1:0) -function test_linspace_identity(r::Range{T}, mr) where T +function test_linspace_identity(r::AbstractRange{T}, mr) where T @test -r == mr @test -collect(r) == collect(mr) @test isa(-r, typeof(r)) @@ -945,7 +945,7 @@ for _r in (1:2:100, 1:100, 1f0:2f0:100f0, 1.0:2.0:100.0, @test isa(float_r, typeof(_r)) @test eltype(big_r) === BigFloat else - @test isa(float_r, Range) + @test isa(float_r, AbstractRange) @test eltype(float_r) <: AbstractFloat @test eltype(big_r) === BigInt end diff --git a/test/sorting.jl b/test/sorting.jl index cc5545e353d04..192b739ef9665 100644 --- a/test/sorting.jl +++ b/test/sorting.jl @@ -95,7 +95,7 @@ end @test searchsortedlast(500:1.0:600, 1.0e20) == 101 # exercise the codepath in searchsorted* methods for ranges that check for zero step range -struct ConstantRange{T} <: Range{T} +struct ConstantRange{T} <: AbstractRange{T} val::T len::Int end diff --git a/test/specificity.jl b/test/specificity.jl index 417af2ed4a43d..67a815cee07ef 100644 --- a/test/specificity.jl +++ b/test/specificity.jl @@ -96,7 +96,7 @@ end # a method specificity issue c99991(::Type{T},x::T) where {T} = 0 c99991(::Type{UnitRange{T}},x::StepRangeLen{T}) where {T} = 1 -c99991(::Type{UnitRange{T}},x::Range{T}) where {T} = 2 +c99991(::Type{UnitRange{T}},x::AbstractRange{T}) where {T} = 2 @test c99991(UnitRange{Float64}, 1.0:2.0) == 1 @test c99991(UnitRange{Int}, 1:2) == 2 diff --git a/test/subtype.jl b/test/subtype.jl index 050dc8af0a6fb..3e68f9ce4d97a 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -646,8 +646,8 @@ function test_intersection() @testintersect(Tuple{Type{Ptr{UInt8}}, Ptr{Bottom}}, (@UnionAll T Tuple{Type{Ptr{T}},Ptr{T}}), Bottom) - @testintersect(Tuple{Range{Int},Tuple{Int,Int}}, (@UnionAll T Tuple{AbstractArray{T},Dims}), - Tuple{Range{Int},Tuple{Int,Int}}) + @testintersect(Tuple{AbstractRange{Int},Tuple{Int,Int}}, (@UnionAll T Tuple{AbstractArray{T},Dims}), + Tuple{AbstractRange{Int},Tuple{Int,Int}}) @testintersect((@UnionAll Integer<:T<:Number Array{T}), (@UnionAll T<:Number Array{T}), (@UnionAll Integer<:T<:Number Array{T}))