XO1402: loop without a provable bound
Every loop of a real-time function (core 6.5) needs a bound known at compile time: a for over a range whose ends are constants is bounded by its length; any other for and every while needs a bound N clause after the iterated value or the condition, N a constant Int. A bound is a contract (core 3.5): when the iteration count is not constant, the loop faults with XO-F006 when it would start iteration N + 1, and xo test fuzzes the function. This code is also reported in any function when a bound is not a constant, is negative, or is smaller than a constant range it bounds.
Example
fn sum(xs: List[Int]) -> Int uses realtime {
var t = 0
for x in xs { t += x }
t
}Fix
const MAX = 64
fn sum(xs: List[Int]) -> Int uses realtime {
var t = 0
for x in xs bound MAX { t += x }
t
}Run xo explain XO1402 for this text in a terminal, or see
section 10.6 of the specification.