0 <= i < xs.len() is refusedOpen and answer this issue on GitHub.
compiler, ready · opened 2026-11-14 · updated 2026-11-22 · 0 comments
A range check is written today as two comparisons joined by &&:
assert(i >= 0 && i < xs.len())
The shorter form from mathematics, which the website already uses in its running text (website/fast/index.html, “where the compiler has proved 0 <= i < xs.len()”), is refused:
fn get(xs: Vec[int], i: int) -> int {
assert(0 <= i < xs.len())
xs[i]
}
fn main() {
println(f"{get(vec[1, 2, 3], 1)}")
}
nikaia run c.nika (binary of 2026-11-14), expected 2, actual:
error: Expected `)` here, but found `<`.
--> c.nika:2:16
The owner wants the chained form shown on the start page and in the README (2026-11-14): it is shorter and reads like the bound it states.
No ADR or part of the specification refuses a chain: the grammar takes at most one comparison (cmp_tail? in cmp_expr_bare, crates/nikaia/src/parser/mod.rs) only because nothing more was decided. The extension:
< and <= mixed, or > and >= mixed, means the single comparisons joined by &&: a <= b < c is a <= b && b < c, and a longer chain a < b <= c < d likewise.&& does. 0 <= f(x) < n calls f once.a < b > c), or holds == or != (a == b == c, a < b == c), stays refused, with an error that names the chain and shows the && form. a == b == c reads as “all three equal” to one reader and as (a == b) == c to another.&& form, so assert(0 <= i < xs.len()) proves xs[i] exactly as assert(i >= 0 && i < xs.len()) does.docs/specification/10-nikaia-light.md, where the comparisons are described) that states D1-D3.cmp_tail* in place of cmp_tail?, and a chain node (or the && form with the middle operand bound once) that keeps D2. A mixed chain of D3 is refused with its own error code (the supervisor reserves it) and the && form in its help.&& form (D4); the emitted Rust binds a middle operand that is not a plain name to a local, so it is evaluated once.tests/compiler/: the probe above (prints 2); a chain of three; a middle operand with a side effect run once; a false first comparison that does not evaluate the last operand; xs[i] proved after assert(0 <= i < xs.len()), with no bounds check left in the emitted Rust; each refused form of D3 with its .stderr.website/index.html, the quicksort asserts) and README.md: write the bounds as chains, assert(0 <= lo <= hi < a.len()), and update tests/page-examples/EXPECTED.txt.assert(0 <= i < xs.len()) builds, runs and proves the index it guards; mixed or == chains are refused with an error that shows the && form; the start page and the README show the chained asserts.
crates/nikaia/src/parser/mod.rs (the grammar block: Rust where the code it changes is Rust), the checker, prover and lowering parts that read a binary &&, docs/specification/10-nikaia-light.md, the new ADR, the tests, website/index.html, README.md, tests/page-examples/EXPECTED.txt. The report lists the Rust it added.
a < b > c, a == b == c): D3 keeps the readings that are not obvious out.&& form: it repeats the middle operand and is longer for the most common bound in the language.Generated by Claude Code