Issue #1993: An either-valued call returned from an owned-result function gets no .into() (comptime program: NK1127, rustc E0308)

Open and answer this issue on GitHub.

ready, bugs · opened 2026-11-17 · updated 2026-11-21 · 3 comments

Found while building “yaml: remove the needless collects and copies” (#1981).

Probe

In packages/yaml/src/main.nika, change uri_decoded’s return s.clone() to return s, then:

cd packages/yaml && nikaia check src/main.nika

Output

4× NK1127 “limits can’t be computed while the program is built” on the default_limits() defaults of documents, read, parse and load. The function means the same as before, so the file should check clean.

The comptime program’s rustc gives E0308 (expected Text, found EitherText<'_>) at return Some(uri_decoded(nikaia_std::index::or(verbatim, || ""))) in resolved. The ledger gives resolved an owned String? result, but uri_decoded returns an either value.

The same happens with invalid_tagged’s text: n.raw.clone() changed to n.raw. It does not reproduce in a standalone program, because there resolved is inferred as returning an either value.

Suspected

crates/nikaia-std/src/compiler/emit_stmt.nika, around line 1376 (call_returns_either): it writes no .into() when an either-valued call is returned from a function with an owned result. Assignments get one from either_back (around line 873).

To build

Done when

The probe checks clean, and the test passes under nikaia test --both-settings.

Comments

keywan-ghadami, 2026-11-21

Brief queued: issue-1993


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #1993

Your work order is issue #1993, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/1993/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/bugs/issue-1993.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-21

Run: issue-1993, Result: partial

Tokens: input 250, cache read 7215609, cache write 154740, output 55365 Cost: 3.96 USD, time 16 min 20 s, turns 125

Report

Result: partial Files: crates/nikaia-std/src/compiler/emit_below.nika crates/nikaia-std/src/compiler/emit_core_flow.nika crates/nikaia-std/src/compiler/emit_core_leaves.nika crates/nikaia-std/src/compiler/emit_stmt.nika crates/nikaia-std/src/compiler/lowered.rs crates/nikaia-std/src/compiler/lowered/emit_below.rs crates/nikaia-std/src/compiler/lowered/emit_core_flow.rs crates/nikaia-std/src/compiler/lowered/emit_core_leaves.rs crates/nikaia-std/src/compiler/lowered/emit_stmt.rs tests/compiler/tests/either_call_returned_owned.nika tests/compiler/tests/either_call_returned_owned.stdout packages/yaml/src/main.nika Commit: An either-valued call handed back from an owned text result is made owned Body: either_into_owned (emit_below.nika) adds .into() after a return of a call whose result is of both kinds, when the function’s own result is owned text and not lent; it is applied in emit_core_handed_back, emit_stmt_expr (tail) and emit_core_return, the same rule either_back applies to an assignment. Before this, a package’s build-time default program (comptime) emitted return Some(uri_decoded(..)) into Option and rustc refused it, so the package drew NK1127. Test either_call_returned_owned builds a rust-library package of the yaml shape and expects exit 0. The yaml uri_decoded clone is dropped; the invalid_tagged clone stays (Found). Part: #1993 Tests: either_call_returned_owned passes --both-settings on target/fast and fails on the old binary (NK1127); cd packages/yaml && nikaia check src/main.nika: no errors, one NK1261 warning that was already there on the old binary; pre-push green; lower-std fixpoint clean Gate: green Deviation: To build (c) is half done: packages/yaml/src/main.nika:2027 keeps text: n.raw.clone(). Without it, Error.text becomes a view (pub struct Error<'a> { text: &'a str }) in the comptime program, and rustc refuses error_of, syntax_error, tags_fit and merge (E0106 missing lifetime specifier). That is not the either-return shape. Found: A struct field declared String, filled from a view of a lent struct's text field, makes the struct a view struct, and that struct thrown out of a by-value caller fails in rustc: probe (target/fast/nikaia run main.nika, HEAD 996553813 + this fix): `struct Node {\n raw: String,\n start: i64,\n}\n\nstruct Error {\n message: String,\n text: String,\n}\n\nimpl Error for Error {\n fn message(ref self) -> String {\n return self.message.clone()\n }\n}\n\nfn parsed(input: String) -> Node sync {\n return Node { raw: input.strip_prefix("!") ?? "", start: 0 }\n}\n\nfn invalid(n: ref Node, core: String) -> Error sync {\n return Error { message: f"`{n.raw}` does not fit {core}", text: n.raw }\n}\n\nfn checked(input: String) -> i64 sync throws {\n let n = parsed(input)\n if n.raw == "x" {\n throw invalid(n, "bool")\n }\n return n.start\n}\n\nfn main() throws {\n let mut s = String()\n s.push_str("!x")\n let r = checked(s) catch { println(error.text); 0 }\n println(r)\n}\n` gives NK1343 "Internal compiler error. Rustc output: lifetime may not live long enough" at `throw invalid(n, "bool")`; it should either run and print x then 0, or refuse at text: n.raw with NK2106 (as it does when Node.raw is owned text, help `n.raw.clone()`); cause unknown, suspected in the view-struct inference of a String field (the struct-field either/view decision, ADR-282 D14); in packages/yaml the same shape (invalid_tagged text: n.raw without .clone()) gives NK1127 via E0106 on Error<'_> Needs: the fix of the NK1343 view-struct defect named in Found, before packages/yaml/src/main.nika:2027 can drop text: n.raw.clone() Changelog: An either-valued call handed back from a function with an owned text result is made owned, so a package whose build-time default program reaches that shape (the yaml package's uri_decoded) no longer draws NK1127 (#1993) Issue: wrong I7: line 2027's clone is not the either-return shape: dropping it makes Error a view struct (E0106 in the comptime program), and only line 2552 is fixed by To build (a) Owner: none Comment: #1993 uri_decoded's clone is gone with the fix; invalid_tagged's text: n.raw.clone() stays: without it Error.text becomes a view and the comptime program fails E0106 (separate defect, filed from this run's Found) Friction: nikaia fmt on crates/nikaia-std/src/compiler/*.nika re-indents the whole file from 4 spaces to tabs (1253-3806 lines per file) and on packages/yaml/src/main.nika rewraps grammar actions, so it can't be run on the edited files; restored each from HEAD and re-applied the edits. A test program's own functions never get a ledger, so the owned-result shape (no returns line) needs a scratch rust-library package; turns went into three single-file shapes that passed on the old binary Disk freed: removed packages/yaml/target and the scratch copies' target/; target/nikaia-project-tests 557M, / 20G free of 252G (50%); no new cache entry over 100 MB Reviewed: 8d5584c9604b38253c5dd2d4a64273f32ea6b21619c7e1b3a1197483b97cb299 Pushed: local 9ed2346f63a9b1bd111f750d2491059581818e97 Attribution: Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UVxJDutPTwP5Xj5HkGuidk

Debrief

  1. What cost the most: finding a test shape that fails on the old binary. Three single-file programs passed on both binaries, because a test program’s functions get no ledger, so the result never counts as owned. Second: nikaia fmt re-indented four compiler files from spaces to tabs, and I restored them from HEAD and re-applied my edits by hand.
  2. What I looked up:
    • The build-time program is compiled where rustc’s output is thrown away (comptime_bundle.nika keeps it in NOT_BUILT). The real error only showed through a RUSTC= wrapper script that saved stderr.
    • Each package keeps its build-time programs in its own target/nikaia/build-time/comptime/, not in ~/.cache.
    • The test pattern that builds a throwaway package (a_dependency_default_beside_...).
  3. Checks:
    • Useful: the old/new A/B run of the test; nikaia check on yaml; the rustc wrapper; lower-std fixpoint; pre-push.
    • Wasted: three single-file test runs that passed on both binaries; the first test that drew NK2302; fmt on the edited compiler files; looking for the build-time program in ~/.cache.
  4. One change: a builder.md line: “NK1127 with ‘this compiler’s fault’: run with RUSTC=<wrapper that tees stderr>. The program is at <pkg>/target/nikaia/build-time/comptime/<hash>/main.rs.”
  5. What the issue lacked:
    • wrong I7: it put both clones on the either-return shape. Line 2027 is a separate defect: Error becomes a struct holding a reference, and rustc reports E0106.
    • broke I5: no probe that fails today. The real shape needs a library package whose ledger records the result as owned.
    • knowledge: Core | a single-file test never reproduces a ledger-pinned owned result; build a scratch rust-library package as a_dependency_default_beside_a_type_error_is_not_refused_again does.
  6. Traps:
    • Fact: Core nikaia fmt re-indents crates/nikaia-std/src/compiler/*.nika to tabs and rewraps yaml grammar actions, so never run it on those files; let pre-push judge fmt on what is staged.
    • Fact: Core NK1127’s “couldn’t build” hides rustc’s error; set RUSTC to a script that appends stderr to a file to see it.
    • Fact: Lowering nikaia check in packages/yaml creates packages/yaml/target (gitignored), so delete it after the run.
  7. Work area: Fact: none. The brief named no topic section and I measured no figures.

Generated by Claude Code

keywan-ghadami, 2026-11-21

From the report of the run of issue-1993 (#1993):

uri_decoded’s clone is gone with the fix; invalid_tagged’s text: n.raw.clone() stays: without it Error.text becomes a view and the comptime program fails E0106 (separate defect, filed from this run’s Found)


Generated by Claude Code

Back to Open Issues