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.
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:
let seen: i64 = n.get() in the first program: accepted, prints 1, exit 0.println(f"{seen}"), with no set at all: the same NK2101. So it is about the task, not the lock door.async(detached) in place of spawn: the same NK2101 (“after a detached task took it”).seen twice to fn take(x: i64) and putting it in two tuples, with no task: accepted, prints 1 1 0 0.SharedMut[Vec[i64]] read with get and used in two spawns: NK2101, rightly, since a Vec moves.No open issue names it (searched the titles for Seen and task).
get hands out Seen[T], and the emitter erases the stamp: a Seen[i64] is an i64 in the language below. D23: the stamp passes through what cannot write it back.Seen[i64] is copied into each task, and the first program prints 1 or 2 (whichever set comes first; the other is overtaken).Traced in the code, not yet in a run; item 1 confirms it with a probe.
a_task_takes_these (around line 175) and takes_of_a_lambda (around line 145) in crates/nikaia-std/src/compiler/check_lambdas.nika record a local as taken when takes_away(world, local.ty) holds.takes_away in crates/nikaia-std/src/compiler/check_values.nika (line 12) starts with moves_away(ty).moves_away in crates/nikaia-std/src/compiler/check_types.nika (line 142): for a Ty::Named it is true unless the name is a number, bool, char, scalar, Shared or SharedMut. Seen is none of these, so Seen[i64] moves away. copies_plainly (line 162) has the same gap. Neither looks through the stamp with Ty::unseen() (crates/nikaia-std/src/compiler/ty.nika), as Ty::fits does.a_task_took_what_is_used_again in crates/nikaia-std/src/compiler/check_takes.nika (around line 885) from ty.shown(), which is why it says Seen[i64].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.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.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.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.1 or 2 and exits 0 at both settings, and nikaia run gives no NK2101 for the variants with a number or a bool.Fixes #N (#N being this issue’s number); the others say Part of #N.Found: line for each defect met on the way.crates/nikaia-std/src/compiler/check_types.nika, and what item 4 names; their lowered .rs is output.tests/compiler/tests/ (the two programs and their .stdout / .stderr).seen fail the same way.