Issue #3008: A list a function returns with a constant length (a literal, [0; 64]) is not known to have that length at the call

Open and answer this issue on GitHub.

ready, bugs, queued · opened 2026-11-30 · updated 2026-11-30 · 0 comments

Probe

Run on develop at 59f3af8d (target/fast/nikaia, built from that tree), outside any project:

// A returned list's length: as a literal, as `[v; n]` with a constant, and
// against a parameter (`ones(n)`, #1756's own probe shape).
pub fn four() -> Vec[u32] {
    return [1, 2, 3, 4]
}

pub fn zeros64() -> Vec[u32] {
    return [0; 64]
}

pub fn ones(n: i64) -> Vec[i64] {
    let mut v: Vec[i64] = []
    for _i in 0..<n {
        v.push(1)
    }
    return v
}

pub fn read(n: i64) -> i64 {
    let k = four()
    let z = zeros64()
    let o = ones(n)
    let mut s = (k[3] as i64) + (z[63] as i64)
    if n > 0 {
        s = s + o[n - 1]
    }
    return s
}

fn main() throws {
    println(f"{read(3)}")
}

nikaia check --bounds p7_returned_len.nika

Expected: all three indexes proved: four() returns a list of 4 elements, zeros64() one of 64, so k[3] and z[63] are inside, as o[n - 1] is.

Actual:

bounds in p7_returned_len.nika: 3 indexes, 1 proved; ...
    23  k[3]           checked: no fact bounds what it reads - a counter, a loop, a length, or one list as long as another (#432, #383, #388)
    23  z[63]          checked: no fact bounds what it reads - ...
    25  o[n - 1]       proved

The governing decision

ADR-306 D23 as built for #1756 (“a returned list’s length against a parameter”, decided by the supervisor 2026-11-16 as the same reading as D23’s bound on a returned value): the caller reads a callee’s found postcondition on what it returns. A length that is a constant is the simpler case of that reading, and it is not carried: only the length against a parameter is.

Found while #2957 (SHA-256 in Nikaia): its round table fn sha256_rounds() -> Vec[u32] (a literal of 64) could not be indexed proved by the compression function, which had to be written with the constants inline.

To build

  1. In the bounds walk’s found postconditions (bounds_*.nika, where #1756 derives a returned list’s length against a parameter): a returned list whose length is a constant on every return (a list literal, [v; n] with n a constant) gets result.len() == N, read at the call as the parameter case is.
  2. A test in tests/compiler/tests/ with the probe above, all three proved.

Done when

The probe prints 3 indexes, 3 proved under --bounds.


Generated by Claude Code

Back to Open Issues