Issue #1062: NK1104: s.to_string() on a for element of a string-literal array is typed ref String

Open and answer this issue on GitHub.

ready · opened 2026-10-31 · updated 2026-10-31 · 0 comments

Found by the builder that reworked scripts/drive.nika (eca460c), which wrote exe.clone() at two call sites to get past it; those come out once this is fixed.

Probe

fn pick() -> String throws {
    for s in ["a", "b"] {
        if s == "b" { return s.to_string() }
    }
    return ""
}

fn take(s: String) throws {
    println(s)
}

fn main() throws {
    let s = pick()
    if s == "" { return }
    let mut i = 0
    while i < 2 {
        take(s.clone())
        i += 1
    }
    take(s)
}

nikaia check: error[NK1104]: You're returning ref String, but the function is declared to return String at s.to_string() (3:30). to_string() gives text of its own; the refusal is wrong.

To build

  1. Find why s.to_string() on a for element of a string-literal array is typed ref String once the caller moves the result after a loop (suspected: the checker’s typing of the literal array’s element; not traced).
  2. Test: the probe in tests/compiler/ with its .stdout (three lines b), at both settings.
  3. Remove the two exe.clone() workarounds in scripts/drive.nika (eca460c).

Generated by Claude Code

Back to Open Issues