diff --git a/base/reinterpretarray.jl b/base/reinterpretarray.jl index 02b354b99cc9b..1d30a16218f2c 100644 --- a/base/reinterpretarray.jl +++ b/base/reinterpretarray.jl @@ -256,7 +256,10 @@ end # `IndexStyle(a) == IndexLinear()`, it's advantageous to retain pseudo-linear indexing. struct IndexSCartesian2{K} <: IndexStyle end # K = aligned_sizeof(S) ÷ aligned_sizeof(T), a static-sized 2d cartesian iterator -IndexStyle(::Type{ReinterpretArray{T,N,S,A,false}}) where {T,N,S,A<:AbstractArray{S,N}} = IndexStyle(A) +# only `IndexLinear` is known to be valid when the axes change (#63305) +IndexStyle(::Type{ReinterpretArray{T,N,S,A,false}}) where {T,N,S,A<:AbstractArray{S,N}} = + IndexStyle(A) === IndexLinear() ? IndexLinear() : IndexCartesian() + function IndexStyle(::Type{ReinterpretArray{T,N,S,A,true}}) where {T,N,S,A<:AbstractArray{S}} if aligned_sizeof(T) < aligned_sizeof(S) IndexStyle(A) === IndexLinear() && return IndexSCartesian2{aligned_sizeof(S) ÷ aligned_sizeof(T)}() diff --git a/test/reinterpretarray.jl b/test/reinterpretarray.jl index 39f994295d3cb..7b895c925dcf9 100644 --- a/test/reinterpretarray.jl +++ b/test/reinterpretarray.jl @@ -880,3 +880,11 @@ end @test !Base.array_subpadding(T_5, S_1_3) @test !Base.array_subpadding(S_1_3, T_5) end + +@testset "issue #63305" begin + a = ones(UInt64, 2) + b = reinterpret(UInt8, reinterpret(reshape, UInt16, a)) + c = collect(b) + @test c[5] == b[5] == 0x00 + @test vec(c) == reinterpret(UInt8, a) +end