Issue #2194: A number read from a lock is taken by a spawned task as if it moved (NK2101 on a Seen[i64]), and the help’s .clone() then draws a warning that it makes nothing new (NK1350)

Open and answer this issue on GitHub.

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

Found while drafting “The lock tests of std move into Nikaia programs” (#2189). No item of it is blocked: its race program (item 5) races two set(…; after:) calls on a literal witness. A program that used n.get() as the witness in two tasks, the natural way to write the race, meets this defect.

What happens today

Binary: target/release/nikaia (nikaia 0.1.0, built 2026-11-18 06:16 from develop), run in a scratch directory outside the checkout with nikaia run FILE. The same message at --user-parallelism no (exit 1) and yes (exit 101; a refused program elsewhere, such as a missing method, exits 1 at yes, so that exit code is a second thing to look at in item 1).

fn main() throws {
    let n: SharedMut[i64] = SharedMut(0)
    let seen = n.get()
    let a = spawn fn { n.set(1; after: seen) catch { return } }
    let b = spawn fn { n.set(2; after: seen) catch { return } }
    a.join()
    b.join()
    println(f"{n.get()}")
}
error[NK2101]: You're using `seen` after a background task took it.
  --> seen.nika:5:24
   |
 5 |     let b = spawn fn { n.set(2; after: seen) catch { return } }
   |                        ^
   |
   = note: A task started with `spawn` may outlive this function, so it takes the variables it uses with it. `seen` is a `Seen[i64]`, so it went to the task.
   = note: Numbers, `bool`s, views and `Shared[T]` handles aren't taken: they're copied.
   = help: Make a copy before and hand over the copy: `let copy = seen.clone()`, then use `copy` inside.
1 value a task took with it

Exit 1 at the default setting. The message contradicts itself: its second note says numbers are copied, and seen is a number. Following the help:

fn main() throws {
    let n: SharedMut[i64] = SharedMut(0)
    let seen = n.get()
    let seen2 = seen.clone()
    println(f"{seen2}")
}
warning[NK1350]: `seen` is an `i64`, which copies by itself: `.clone()` makes nothing new.
  --> seen_clone.nika:4:17
   |
 4 |     let seen2 = seen.clone()
   |                 ^^^^^^^^^^^^
   |
   = note: A number, a `bool`, a `char` and a type whose every part copies are copied wherever they are read (ADR-294 D9.1).
   = help: Delete `.clone()`.
0

Variants, each run the same way:

No open issue names it (searched the titles for Seen and task).

Expected

Cause

Traced in the code, not yet in a run; item 1 confirms it with a probe.

To build

  1. Confirm the cause: nikaia run scripts/where.nika -- moves_away and a probe that shows moves_away true for Seen[i64] and false for i64. A cause shown false is answered wrong I7: ... in the report.
  2. Make moves_away and copies_plainly judge a stamped type by what it holds (ty.unseen()), so a Seen[T] moves exactly when T does. Test: tests/compiler/tests/a_number_read_from_a_lock_is_copied_into_two_tasks.nika with its .stdout: the first program above with spawn, a second pair with async(detached), and a bool read with get; each prints its result, at both settings.
  3. Keep the move of a stamped value that does move. Test: tests/compiler/tests/a_list_read_from_a_lock_is_taken_by_the_first_task.nika with its .stderr: a Seen[Vec[i64]] used in two spawns gives NK2101, its note naming the type.
  4. Sweep for the rule (I10): the other callers of moves_away and copies_plainly (in check_core_call_on.nika, check_core_flow.nika, check_core_leaves.nika, check_types.nika, check_values.nika and emit_exprs.nika, 14 call sites) and any other test of a type’s name that misses Seen. Name each one checked in the report; one that changes behaviour gets its case in the test of item 2.

Done when

Files and limits

Ruled out

Back to Open Issues