Open
Description
Because of how MemoryRef
s can represent views and because the MemoryRef itself is not captured in BoundsErrors, we can get confusing errors like this:
julia> x = Memory{Int}([1,2,3,4])
4-element Memory{Int64}:
1
2
3
4
julia> copyto!(x, 3, x, 3, 3)
ERROR: BoundsError: attempt to access MemoryRef{Int64} at index [3]
Stacktrace:
[1] memoryref
@ ./boot.jl:524 [inlined]
[2] unsafe_copyto!
@ ./genericmemory.jl:115 [inlined]
[3] unsafe_copyto!
@ ./genericmemory.jl:139 [inlined]
[4] copyto!(dest::Memory{Int64}, doffs::Int64, src::Memory{Int64}, soffs::Int64, n::Int64)
@ Base ./genericmemory.jl:175
[5] top-level scope
@ REPL[1]:1
This example is confusing because one could think that the memory has length 4 so accessing it at index 3 should be fine. What's happening is that a MemoryRef is constructed at an offset and then indexed out of bounds at index 3 when the new MemoryRef only has two indices.