Slide 9 of 37
Bounds, proved at compile time
proc main(): void {
v := ["a", "b", "c"]
last := len(v) - 1
if v bounds last {
echo v[last] // fine — the guard covers it
}
}
A dedicated flow-sensitive pass proves every index and slice in range before the program ever runs. A literal index into a known length compiles outright; a computed index has to sit under a guard the pass can read, such as `if v bounds i { v[i] }` — sugar for `i >= 0 && i < len(v)`. Anything the pass cannot prove safe is a compile error, not a runtime panic — `echo v[len(v) - 1]` on its own is rejected outright, computed index and all. This very server leans on it: the slide number from the URL is checked with exactly this guard before it ever indexes the list of slides.