agent: builder model: opus max_turns: 80 budget_usd: 15 —

Brief: #1034 step 2, a fn parameter captured by a lambda the function hands out is kept (rustc)

Score: compiler bug (false acceptance: nikaia check passes, rustc refuses; every function that builds a function value from one it is given), bugs-first default of docs/priorities.md. Step 1 built in ec386c71 (b1034a); this is the issue’s last step.

Issue #1034 (copied, step 2; corrected and widened by the architect at 3ebedbca)

Part I 5.4: a function value in a result or a field is kept, and a parameter the body keeps (“stores, hands back, gives to a task”) is detached and moves; only a parameter that only runs it is lent. A lambda handed out that captures a fn parameter keeps it, but the parameter is lowered as run-only f: &impl AsyncFn(i64) -> i64.

Cause traced (row a): run_code (check_function.nika:767-776) holds every fn parameter not in check_function_keeps(world, key) (:470, the contract’s keeps), and the lowering reads the same keeps (emit_core_args.nika:183, emit_misc.nika:361, emit_reach.nika:236). keeps is computed by the walk in keeps.nika: return f and return Box2 { run: f } keep f (probed, both run: hand_over/reached_of :179/:190, classify :525 for a struct literal), but a closure handed out is not walked for the parameters it names. keeps_named_by_a_lambda (:929) does exactly that walk, and today is used only for call arguments (keep_argument :628, and :773).

Locations

To build

  1. Test tests/compiler/tests/a_returned_lambda_keeps_its_fn_parameter.nika + .stdout (3, 7, 7, 4, one a line), the program below; run by the architect at 3ebedbca: nikaia check passes, nikaia run gives rustc errors at lines 6, 10, 14 and 23. Commit keeps: a lambda handed out keeps the fn parameters it names (#1034), Fixes: #1034.
struct Box2 {
    run: fn(i64) -> i64,
}

fn plus_one(f: fn(i64) -> i64) -> fn(i64) -> i64 {
    return fn(x) { f(x) + 1 }
}

fn boxed(f: fn(i64) -> i64) -> Box2 {
    return Box2 { run: fn(x) { f(x) + 1 } }
}

fn twice(f: fn(i64) -> i64) -> fn(i64) -> i64 {
    return fn(x) { f(f(x)) }
}

fn main() {
    let p = plus_one(fn(x) { x * 2 })
    println(f"{p(1)}")
    let b = boxed(fn(x) { x * 3 })
    println(f"{b.run(2)}")
    let add = fn(x) { x + 3 }
    let t = twice(add)
    println(f"{t(1)}")
    println(f"{add(1)}")
}

Traced to the named cause: row a (plus_one, line 6: f lowered &impl AsyncFn, so f(x) is a CallRefFuture and + 1 fails). Rows b (boxed, line 10) and c (twice with a kept local, lines 14 and 23, rustc: Future not implemented for i64) are unverified to share it. If one row has a second cause, name it and its rustc message under Found:, commit the test without that row, and say so in Body: (and write Part: #1034 then, not Fixes).

Do not write same(inc)(1) (a call of a call’s result): the parser refuses it, open as #1042 (decision).

Done when

The test passes through nikaia test and fails on the unfixed compiler; the step 1 test, a_kept_fn_copied_from_a_name_or_field, and the tests nikaia run scripts/where.nika -- keeps_named_by_a_lambda run_code lists still pass; lower-std fixpoint clean; cargo build --profile fast -p nikaia; the guard set of .claude/agents/builder.md green; pushed. A run-only parameter must stay lent: fn apply(f: fn(i64) -> i64, x: i64) -> i64 { return f(x) } still lowers f as &impl AsyncFn (check with nikaia lower, say so under Tests:). Changelog: one line (a function that hands out a lambda capturing one of its fn parameters keeps that parameter, instead of a lowering rustc refused). Stop about 15 turns before max_turns, commit what is finished and report partial.

Stop and report if

An edit is needed outside keeps.nika, check_function.nika, their lowered files (and lowered.rs), files lower-std rewrites because of your change (contracts, ledgers) and the new test; an error in another agent’s file. Known: the uncommitted text_tiers.nika (#999, the yaml lane’s) in the shared tree makes 10 tests/compiler tests refuse NK2302 at src/main.nika:13: not yours, not a Found:, name it under Tests:.

Not yours, never stage: every file git status shows modified or untracked at your start, and every docs/briefs/* file except your report.

Rules (CLAUDE.md; this block is pasted into every brief, also a fix-forward)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/b1034b-returned-lambda-keeps-param.md.report.md)

Fields of docs/architect.md, Briefs and reports: Result: done|noop|partial|blocked (the bare word alone on that line: Result: done, never a summary after it, which cuts the batch, b869a 2026-10-27; Owner: is a question for the owner or none, never a role), Files, Commit, Body (optional, one paragraph for the commit message), Fixes, Pushed, Tests, Gate (green|red), Deviation, Found, Needs, Changelog, Owner, Disk freed, and for a move Rs2nika: (the kept N of M lines of rs2nika --score, then the three costliest hand edits; none for a task that moves no Rust, none (redesign) for a brief with Shape: redesign and no Convert: line). none where nothing, and then the bare word: Deviation: none (a note) cuts the batch (batch.nika compares exactly); a note goes into the commit message. Found: is only for a defect outside your change (it cuts the batch); a process event such as another session resetting or rewriting your files is no Found:, it goes under Needs: (m3a 2026-10-28); a converter draft that came out wrong is no Found:, it is one of the costliest edits under Rs2nika:, which the converter lane reads (e12-4b 2026-10-27); how you solved your own step goes into the commit message. Deviation: is only a step of the brief built otherwise than written or not built (a choice the brief left to you, such as keep what X needs and say so, is no deviation: it goes into the commit message; nor is building two steps in one commit when every step is built, e12-3a 2026-10-27, nor a step another commit on develop already built, shown by your test failing with that commit’s change reverted, b889 2026-10-27: name the commit in Body:, nor a test’s expected .stdout/.stderr taken from what the program really prints where the brief’s sketch of it was short or wrong, b934 2026-10-29: say so in Body:, nor a lowering that follows the ADR governing it where the brief’s expected lowering contradicts that ADR, b933 2026-10-29: name the ADR in Body:, nor a lowering other than the brief’s where rustc cannot take the brief’s, b1029 2026-10-31: say why in Body:, nor re-keying an allow-list entry (KNOWN) whose hash changed for the same program and the same reason, b-fixforward-sweep2 2026-10-28: say so in Body:, nor an existing test’s expected .stdout/.stderr updated because your change rightly changes the message it prints, b1012b 2026-10-31: name the test in Body:); how you verified (e.g. a test not run against the unfixed compiler) goes under Tests:. A noop says why under Tests: (what was probed), not under Deviation:. Final answer, one line: done <sha>, report <path> (or BLOCKED: ... / PUSH REJECTED ...).

Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01GFeMqxRbtUMiGVyDMxsvEq

This site is open source. Improve this page.