-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MemoryRef
bounds errors can be confusing
#57184
Comments
It is captured, it is just that people decided it wasn't helpful to display the object that errored, and changed it to only print the type as a summary of it (although also that the
|
Oh, delightful! This issue is very actionable with a better special case for displaying bounds errors on MemoryRef objects. |
Or improve |
I was attempting to take a shot at this, but I'm not sure how to safely figure out how many "remaining" elements in the I say this because I don't imagine replacing the error like this example will be helpful at all, since it is won't be clear what the problem is. julia> x = Memory{Int}([1,2,3,4])
julia> copyto!(x, 1, x, 4, 2)
ERROR: BoundsError: attempt to access MemoryRef{Int64} at index [2]
# replace with this
ERROR: BoundsError: attempt to access a 4-element MemoryRef{Int64} at index [2]
# compared with
julia> SubString("1234", 4)[2]
ERROR: BoundsError: attempt to access 1-codeunit SubString{String} at index [2] and so I was looking into trying to "count" the remaining elements that can be safely accessed such that:
Note that in my example, the error is thrown from a call to |
The way to do this safely is to use |
thanks @oscardssmith! its a bummer that this was not discoverable using maybe it'd be a good idea to leave some "see also" hints in |
seems like a good doc improvement. |
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: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.
The text was updated successfully, but these errors were encountered: