Issue #2518: A type whose mut self method throws keeps its rule as a fact: the rule is checked before each call that may fail

Open and answer this issue on GitHub.

blocked, solver · opened 2026-11-21 · updated 2026-11-23 · 3 comments

Part of #714

What it is

A struct whose method changes self and throws keeps no rule as a fact today (98a8e39a, ADR-369 D3): a failing call left the method with the rule broken, and the caller could catch the error and go on. Such a type could keep its facts if the rule were checked at each call inside the method that may fail, so the rule holds at every throw as ADR-369 D2 requires. That needs the pass to know which calls fail. Governing decision: ADR-369 D2 (the rule holds at each return and each throw of a method that changes the value) and D3.

To build

  1. The rule is checked before each call that may fail in a mut self method that throws, and the type keeps its rule as a fact at entry (the entry fact 98a8e39a drops comes back). Test in tests/compiler/tests/: a mut self method that breaks the rule, then calls a throwing function, and a caller that catches the error and indexes with the rule’s bound: the check fires with the rule’s message before the call; with the rule restored before the call, the index is proved.

Done when

A type with a mut self method that throws keeps its written rule as a fact at its methods’ entries, and a test shows the rule checked before a call that may fail and the caller’s index proved; the commit carries this issue’s Fixes line.

Split from #714 by Claude Code

Comments

keywan-ghadami, 2026-11-23

Brief queued: issue-2518


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

Issue #2518

Your work order is issue #2518, 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/2518/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/solver/issue-2518.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-23

Run: issue-2518, Result: blocked

Tokens: input 36, cache read 760704, cache write 45941, output 8869 Cost: 0.74 USD, time 1 min 51 s, turns 18

Report

Result: blocked Files: none Commit: none Body: nothing built or committed. The rule pass runs right after parsing (crates/nikaia/src/parser/mod.rs:875 type_rules::expand -> crates/nikaia-std/src/compiler/type_rules.nika tr_expand). A call in Nikaia carries no mark when it can fail; whether it fails comes from the whole-program throws inference (contracts/throws.rs, check_may_fail.nika, prover_walk.nika prover_throws), and that runs after this pass. So the pass cannot tell which calls to put the rule’s assert before. Pushed: none Tests: none run (nothing changed) Gate: green Deviation: none Found: the rule pass cannot see which calls fail (traced: tr_expand in crates/nikaia-std/src/compiler/type_rules.nika runs on the parsed tree, before name resolution and throws inference; tr_fails_changed reads only the method’s can_throw flag). Building #2518 needs one of these, and no ADR or issue picks one, no decision yet: (a) put the assert before every call in a mut self throwing method, marked, and let the checker, prover and emitter drop it where prover_throws says the call cannot fail (crosses type_rules, check, prover and emit); (b) put the rule asserts in after throws inference, a new step in the pipeline after checking; (c) put the assert before every call that is not a known non-throwing call in the same file. (c) fires on correct programs, e.g. let x = self.slots.pop() ?? 0 then self.slots.push(x) under assert(slots.len() == 4) would stop before push, which ADR-369 D2 allows (“may be broken for a while”). Probe today: struct Ring { slots: Vec[i64], assert(slots.len() == 4; message: "four slots") } with fn swap_last(mut self, n: i64) throws { let x = self.slots.pop() ?? 0; let y = fail(n); self.slots.push(x + y) }: since 98a8e39a, self.slots[3] in another method of Ring gets no entry fact. That is by design until the decision. Needs: supervisor decision: how the ADR-369 rule pass learns which calls may fail in a mut self method that throws, from (a) a marked assert that later passes drop, (b) inserting the asserts after throws inference, or another way. Also whether checking before a failing call narrows ADR-369 D2’s “may be broken for a while” (an ADR-369 amendment) Changelog: none Issue: broke I7: “That needs the pass to know which calls fail” names the gap but gives no way to close it, and the pass runs before throws inference, so the To build cannot be built without a design decision; broke I4: no probe, the test’s program is only described Owner: none Comment: none Friction: none Disk freed: none; target/nikaia-project-tests 1.8G, / 11G free of 252G Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwk9ubq9teP7QCErff

Debrief

  1. What cost the most: finding where the rule pass sits in the compiler, and whether it can know which calls fail. The Rust file type_rules.rs that 98a8e39a changed is now only an adapter; the code moved to type_rules.nika. Then I had to confirm that the pass runs at parse time, before throws inference. That took about 10 turns.
  2. What the brief could have handed me: the pass’s place in the pipeline (parser/mod.rs:875, before checking) and where the compiler decides that a call fails (prover_throws, check_may_fail.nika, contracts/throws.rs).
  3. Checks run: the binary-freshness check, the outline, the searches and one probe. The probe was half wasted: throw "text" drew NK1161, and the method’s exit claim covered up the index I meant to show. I ran no build or tests, which was right for a blocked run.
  4. One change that would save the most: builder.md could say that an issue whose What it is says “needs the pass to know X” must say where X comes from in the pipeline. Without that, the run should be sent back as a decision before a builder starts.
  5. What the issue lacked. I cited I4 and I7 without reading docs/issues.md, so check those numbers.
    • broke I7: it names the gap (“needs the pass to know which calls fail”) but neither traces nor suggests how the pass could know it.
    • broke I4: no probe; the test program is only described.
    • rules-gap: no rule asks an issue that tightens an ADR decision (here D2’s “may be broken for a while”) to say whether the ADR needs an amendment.
    • knowledge: Core | The ADR-369 rule pass runs on the parsed tree before name resolution and throws inference, so it knows only a function's own throws flag.
  6. Fact: Probes | A probe's throw needs an error value, not text: throw “x” is NK1161. Fact: Probes | probe.nika –file takes only a path below the working directory, so copy a scratchpad file to target/ first.
  7. Fact: Ledger and bounds proofs | A type's rule is written out by crates/nikaia-std/src/compiler/type_rules.nika (tr_expand, tr_rewrite_body, tr_fails_changed), called from parser/mod.rs:875; the Rust type_rules.rs is only the adapter (seen 2026-11-23 at 8c6d2bc37). Fact: Ledger and bounds proofs | Whether an expression can fail is known only to prover_walk.nika prover_throws and the checker's ledger, not before checking (2026-11-23, 8c6d2bc37).

Generated by Claude Code

keywan-ghadami, 2026-11-23

Driver: not queued, this issue waits for #2788, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

Back to Open Issues