diff --git a/base/reshapedarray.jl b/base/reshapedarray.jl index 0cd276be6494f..63e508e8835de 100644 --- a/base/reshapedarray.jl +++ b/base/reshapedarray.jl @@ -238,7 +238,8 @@ offset_if_vec(i::Integer, axs::Tuple) = i @inline function isassigned(A::ReshapedArrayLF, index::Int) @boundscheck checkbounds(Bool, A, index) || return false - @inbounds ret = isassigned(parent(A), index) + indexparent = index - firstindex(A) + firstindex(parent(A)) + @inbounds ret = isassigned(parent(A), indexparent) ret end @inline function isassigned(A::ReshapedArray{T,N}, indices::Vararg{Int, N}) where {T,N} diff --git a/test/abstractarray.jl b/test/abstractarray.jl index a07c0f79a9c25..e6bf0a9f24c11 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -2052,8 +2052,10 @@ end end @testset "reshape for offset arrays" begin - r = reshape(Base.IdentityUnitRange(0:1), (2,1)) - @test r[eachindex(r)] == [0:1;] + p = Base.IdentityUnitRange(3:4) + r = reshape(p, :, 1) + @test r[eachindex(r)] == UnitRange(p) + @test collect(r) == r struct ZeroBasedArray{T,N,A<:AbstractArray{T,N}} <: AbstractArray{T,N} a :: A @@ -2069,7 +2071,7 @@ end Base.setindex!(z::ZeroBasedArray{<:Any, N}, val, i::Vararg{Int,N}) where {N} = parent(z)[map(x -> x + 1, i)...] = val z = ZeroBasedArray(collect(1:4)) - r2 = reshape(z, (4, 1)) + r2 = reshape(z, :, 1) @test r2[CartesianIndices(r2)] == r2[LinearIndices(r2)] r2[firstindex(r2)] = 34 @test z[0] == 34