Issue #2191: Joining tasks held in a list fails with NK1343

Open and answer this issue on GitHub.

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

Found while drafting “The Rust tests of fs.rs move into Nikaia: programs that see file names, writes, mappings and roots” (not filed yet); its test 11 (many_threads_reading_and_writing_at_once_each_get_their_own_answer) joins with tasks.drain() and does not wait for this fix. Part of “Unobservable std tests” (#2088).

What happens today

Run on the release binary of 2026-11-18 (develop 690857c2), from a scratch directory, with the shared checkout’s target/release/nikaia. Command: nikaia run join2.nika.

fn main() throws {
    let mut tasks = []
    for t in 0..<2 { tasks.push(spawn fn { t }) }
    let mut total = 0
    for task in tasks { total += task.join() }
    println(f"total: {total}")
}

Expected (ADR-094 D4: the for lends each task, and joining takes it away, which is written tasks.drain()): a refusal by the checker at line 5, NK1131 (“You can’t give away task here: it is an element of tasks, which is only borrowed.”), whose help names tasks.drain(); a task has no .clone(), so the help offers only the drain. Written with for task in tasks.drain(), the program prints:

total: 1

Actual:

error[NK1343]: Internal compiler error.
 5 |     for task in tasks { total += task.join() }
   = note: Rustc output: cannot move out of `*task` which is behind a shared reference.

Shapes run today:

Governing decision

ADR-094 D4: “for x in xs { … } iterates views of xs’s elements and leaves xs where it was … Iteration that takes the elements away is written — for x in xs.drain()”. NK1131 is the refusal for giving away an element of a lent list (check_core_a_lent_place_given_away, its help: “take the elements out of {list} with {list}.drain()”). An internal compiler error is never the answer to a program the checker should refuse.

Cause, traced

The lowered loop (tasks.rs, line 31, of the 8-task program):

for task in tasks.iter() { total += task.join().await?; }

emit_stmt_for (crates/nikaia-std/src/compiler/emit_stmt.nika:1136) writes .iter() for a for over a place that the checker did not put in facts.owned_loops (ADR-094 D4; only a name holding a sequence is handed over, ADR-293 D19, check_core_stmt.nika:2243). FailingTask::<T, E>::join (crates/nikaia-std/src/task.rs) takes self, so rustc refuses the move out of &FailingTask.

The checker lets it through: check_core_a_lent_place_given_away (crates/nikaia-std/src/compiler/check_core_leaves.nika:151) is reached for a value handed back (line 73) and for an argument passed to a parameter that owns it (line 103), not for the receiver of join, which takes its task. Suspected beyond that: whether every std method that takes its receiver (join of each task kind, close of a writer) misses NK1131 the same way; the check that settles it is a probe per method over a lent list of that type, run before the fix.

To build

  1. NK1131 for the receiver of join on an element of a lent list (and of every std method found by the check above to take its receiver), with the help naming {list}.drain() and no .clone() for a type that has none. The change is in crates/nikaia-std/src/compiler/check_core_leaves.nika and the place the checker reads a method’s receiver (check_core_method.nika / check_core_call_on.nika), with crates/nikaia-std/src/compiler/lowered/ as output.
  2. Test a_task_in_a_lent_list_is_joined_by_drain.nika in tests/compiler/tests/: the probe above, with .stderr holding the NK1131 refusal at line 5 and its help naming tasks.drain(). It fails on today’s binary (NK1343).
  3. Test a_list_of_tasks_is_joined_in_a_drain_loop.nika: the same program with for task in tasks.drain(), .stdout holding the row total: 1. It passes today and guards the way the help names.

Done when

nikaia test gives the NK1131 refusal of item 2 (no NK1343) and the row total: 1 of item 3. One commit carries Fixes with the fix and both tests. The report has one Found: line per finding, one per std method the check finds missing NK1131.

Files and limits

Back to Open Issues