diff --git a/base/abstractarray.jl b/base/abstractarray.jl index cfc5078cb005e..f946b1458a776 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -95,7 +95,7 @@ julia> axes(A) """ function axes(A) @inline - map(oneto, size(A)) + map(unchecked_oneto, size(A)) end """ diff --git a/base/range.jl b/base/range.jl index e6341003d0c5a..9f5dd214d67bb 100644 --- a/base/range.jl +++ b/base/range.jl @@ -447,7 +447,7 @@ distinction that the lower limit is guaranteed (by the type system) to be 1. """ struct OneTo{T<:Integer} <: AbstractUnitRange{T} - stop::T + stop::T # invariant: stop >= zero(stop) function OneTo{T}(stop) where {T<:Integer} throwbool(r) = (@noinline; throw(ArgumentError("invalid index: $r of type Bool"))) T === Bool && throwbool(stop) @@ -463,6 +463,8 @@ struct OneTo{T<:Integer} <: AbstractUnitRange{T} T === Bool && throwbool(r) return new(max(zero(T), last(r))) end + + global unchecked_oneto(stop::Integer) = new{typeof(stop)}(stop) end OneTo(stop::T) where {T<:Integer} = OneTo{T}(stop) OneTo(r::AbstractRange{T}) where {T<:Integer} = OneTo{T}(r) @@ -703,8 +705,6 @@ step(r::LinRange) = (last(r)-first(r))/r.lendiv step_hp(r::StepRangeLen) = r.step step_hp(r::AbstractRange) = step(r) -axes(r::AbstractRange) = (oneto(length(r)),) - # Needed to ensure `has_offset_axes` can constant-fold. has_offset_axes(::StepRange) = false diff --git a/test/testhelpers/InfiniteArrays.jl b/test/testhelpers/InfiniteArrays.jl index 14b2e56daf1c6..cec3c94aaa296 100644 --- a/test/testhelpers/InfiniteArrays.jl +++ b/test/testhelpers/InfiniteArrays.jl @@ -48,5 +48,6 @@ Base.length(r::OneToInf) = Infinity() Base.last(r::OneToInf) = Infinity() Base.unitrange(r::OneToInf) = r Base.oneto(::Infinity) = OneToInf() +Base.unchecked_oneto(::Infinity) = OneToInf() end