diff --git a/base/subarray.jl b/base/subarray.jl index 6f1e20af2b966..7b7e913332aaf 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -338,7 +338,9 @@ function getindex(V::FastContiguousSubArray, i::Int) end # parents of FastContiguousSubArrays may support fast indexing with AbstractUnitRanges, # so we may just forward the indexing to the parent -function getindex(V::FastContiguousSubArray, i::AbstractUnitRange{Int}) +# This may only be done for non-offset ranges, as the result would otherwise have offset axes +const OneBasedRanges = Union{OneTo{Int}, UnitRange{Int}, Slice{OneTo{Int}}, IdentityUnitRange{OneTo{Int}}} +function getindex(V::FastContiguousSubArray, i::OneBasedRanges) @inline @boundscheck checkbounds(V, i) @inbounds r = V.parent[V.offset1 .+ i] diff --git a/test/offsetarray.jl b/test/offsetarray.jl index e2924ac0a8ca4..9d6a8b08c0b1f 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -864,3 +864,8 @@ end # this is fixed in #40038, so the evaluation of its CartesianIndices should work @test CartesianIndices(A) == CartesianIndices(B) end + +@testset "indexing views (#53249)" begin + v = view([1,2,3,4], :) + @test v[Base.IdentityUnitRange(2:3)] == OffsetArray(2:3, 2:3) +end