Issue #1145: A while true left only by return in a throws function is warned “Unreachable call”

Open and answer this issue on GitHub.

ready · opened 2026-11-01 · updated 2026-11-01 · 0 comments

Found while cleaning scripts/drive.nika (drive_ci_poll, fa43700f): a false warning. The same function without throws gets no warning.

Probe

use std::process

fn pick(n: i64) -> (String, bool) throws {
    let mut i = 0
    while true {
        let r = process::run("true", [])
        i += 1
        if r.ok && i > n { return ("done", true) }
    }
}

fn main() throws {
    let (s, b) = pick(2)
    println(f"{s} {b}")
}

nikaia run prints done true, but first warning: Unreachable call. pointing at while true { (4:5). Expected: no warning. Without throws (and without process::run) there is no warning.

Suspected cause: the lowering puts the throws result wrapping (an Ok(..) or a call after the loop) behind a loop that never ends, and rustc’s unreachable_code warning is mapped back onto the loop.

To build

  1. In a throws function, emit nothing reachable after a loop that never falls through (while true with no break), or allow rustc’s warning there. Add the probe as tests/compiler/tests/while_true_returns_in_throws_fn.nika with its .stdout and no warning on stderr.

Back to Open Issues