-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]error messagesBetter, more actionable error messagesBetter, more actionable error messagesfeatureIndicates new feature / enhancement requestsIndicates new feature / enhancement requestsneeds pkgevalTests for all registered packages should be run with this changeTests for all registered packages should be run with this changetestThis change adds or pertains to unit testsThis change adds or pertains to unit tests
Description
A bounds error of the form x[out_of_bounds_index] = 0 is very different from a bounds error of the form @inbounds x[out_of_bounds_index] = 0. The former throws a bounds error and the latter is UB.
When --check-bounds=yes, I would like @inbounds x[out_of_bounds_index] = 0 to throw an UnsafeBoundsError or somesuch.
This will enable testing that no unsafe @inbounds usage is hit in a test while still allowing bounds errors. For example this currently passes with --check-bounds=yes and is UB by default:
struct OffsetVector <: AbstractVector{Int}
x::Vector{Int}
offset::Int
end
Base.axes(x::OffsetVector) = (x.offset:x.offset+length(x.x),)
function Base.getindex(x::OffsetVector, i::Int)
checkbounds(x, i)
@inbounds x.x[i-x.offset]
end
x = OffsetVector([1,2,3], 5);
@test_throws BoundsError x[5]
@test_throws BoundsError x[9]I'd like x[5] to throw an UnsafeBoundsError error and fail the test.
KristofferC
Metadata
Metadata
Assignees
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]error messagesBetter, more actionable error messagesBetter, more actionable error messagesfeatureIndicates new feature / enhancement requestsIndicates new feature / enhancement requestsneeds pkgevalTests for all registered packages should be run with this changeTests for all registered packages should be run with this changetestThis change adds or pertains to unit testsThis change adds or pertains to unit tests