diff --git a/base/range.jl b/base/range.jl index d12a10518cd7f7..f3def4549a13a8 100644 --- a/base/range.jl +++ b/base/range.jl @@ -1289,10 +1289,8 @@ AbstractUnitRange{T}(r::AbstractUnitRange{T}) where {T} = r AbstractUnitRange{T}(r::UnitRange) where {T} = UnitRange{T}(r) AbstractUnitRange{T}(r::OneTo) where {T} = OneTo{T}(r) -OrdinalRange{T1, T2}(r::StepRange) where {T1, T2<: Integer} = StepRange{T1, T2}(r) -OrdinalRange{T1, T2}(r::AbstractUnitRange{T1}) where {T1, T2<:Integer} = r -OrdinalRange{T1, T2}(r::UnitRange) where {T1, T2<:Integer} = UnitRange{T1}(r) -OrdinalRange{T1, T2}(r::OneTo) where {T1, T2<:Integer} = OneTo{T1}(r) +OrdinalRange{T, S}(r::OrdinalRange) where {T, S} = StepRange{T, S}(r) +OrdinalRange{T, T}(r::AbstractUnitRange) where {T} = AbstractUnitRange{T}(r) function promote_rule(::Type{StepRange{T1a,T1b}}, ::Type{StepRange{T2a,T2b}}) where {T1a,T1b,T2a,T2b} Tb = promote_type(T1b, T2b) diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 7621e140136275..515e0491ee994e 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -788,7 +788,7 @@ end end end -@testset "proper patition for non-1-indexed vector" begin +@testset "proper partition for non-1-indexed vector" begin @test Iterators.partition(OffsetArray(1:10,10), 5) |> collect == [1:5,6:10] # OffsetVector @test Iterators.partition(OffsetArray(collect(1:10),10), 5) |> collect == [1:5,6:10] # OffsetVector @test Iterators.partition(OffsetArray(reshape(1:9,3,3), (3,3)), 5) |> collect == [1:5,6:9] #OffsetMatrix @@ -822,3 +822,12 @@ end @test (@view x[end, -y[end]])[] == 3 @test (@view x[y[end], end])[] == 4 end + +@testset "CartesianIndices (issue #40035)" begin + A = OffsetArray(big(1):big(2), 0); + B = OffsetArray(1:2, 0); + # axes of an OffsetArray may be converted to an AbstractUnitRange, + # but the conversion to an OrdinalRange was not defined. + # this is fixed in #40038, so the evaluation of its CartesianIndices should work + @test CartesianIndices(A) == CartesianIndices(B) +end diff --git a/test/testhelpers/OffsetArrays.jl b/test/testhelpers/OffsetArrays.jl index 27c666c9dacbd8..e71ec28ad46e58 100644 --- a/test/testhelpers/OffsetArrays.jl +++ b/test/testhelpers/OffsetArrays.jl @@ -44,6 +44,9 @@ function IdOffsetRange{T}(r::IdOffsetRange) where T<:Integer end IdOffsetRange(r::IdOffsetRange) = r +AbstractUnitRange{T}(r::IdOffsetRange{T}) where {T} = r +AbstractUnitRange{T}(r::IdOffsetRange) where {T} = IdOffsetRange{T}(r) + # TODO: uncomment these when Julia is ready # # Conversion preserves both the values and the indexes, throwing an InexactError if this # # is not possible.