Thank you Yichao.
yasm (Yet Another Stupid Mistake)
For the record, here’s a modified example showing @inbounds working as expected.
struct MyType end
Base.checkbounds(A::MyType, i::Integer) = println("checking bounds ...")
function Base.getindex(A::MyType, i::Integer)
@boundscheck checkbounds(A, i)
return 17
end
function f(A::MyType)
s = 0
for i in 1:10
s += A[i]
end
return s
end
function g(A::MyType)
s = 0
for i in 1:10
@inbounds s += A[i]
end
return s
end
A = MyType()
f(A) # performs bounds checking
g(A) # does not perform bounds checking