Issue #1067: NK1102: the result of fn f() -> String { return "lit" } is taken for a view when an owning parameter keeps it

Open and answer this issue on GitHub.

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


agent: builder model: opus max_turns: 60 budget_usd: 12 — Facts: Where things live, Traps already met, Commands

Problem. A function declared -> String hands back text of its own (Part I 2.2), whatever its body returns. When its body returns a literal, the checker treats the call’s result as a view (ref String) and refuses it for an owning parameter. Found by the supervisor’s script builders (2026-10-31).

Probe (0.0.1322):

fn limit() -> String { return "5G" }

fn keep(v: Vec[String], s: String) -> i64 {
    let mut w = v.clone()
    w.push(s)
    return w.len()
}

fn main() {
    println(f"{keep([], limit())}")
}

Refused: NK1102: keep expects s to be String, but you're passing ref String … “This is a view”. Expected: prints 1. (fn take(s: String) -> i64 { return s.len() } with take(limit()) is accepted, so the refusal comes from the “keeps its s after the call” rule meeting a result the checker wrongly calls a view.)

Suspected location (low confidence): the checker’s view facts for a call result (check_references.nika, and wherever a function’s result is marked as a view of static text from its return literal); a declared -> String result is owned, a -> ref String one is a view.

To build

  1. The call’s result of a -> String function is owned at every call site. Test tests/compiler/tests/string_result_of_literal_is_owned.nika + .stdout (the probe).
  2. The view tests still pass (by name: view, 1102, owned).

Generated by Claude Code

Back to Open Issues