Issue #2788: type rules: the ADR-369 rule asserts go in after throws inference, before each call that may fail in a mut self method that throws

Open and answer this issue on GitHub.

ready, solver · opened 2026-11-23 · updated 2026-11-23 · 1 comment

Filed by the driver from the Found: of the run of issue-2518 (#2518) (owner, 2026-11-06).

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)

To build

Done when

The probe or check gives the expected output the first item names from its ADR or Part I-III section, and a tests/compiler/tests/ test (or the named check) that failed on the unfixed tree is green; or the probe already passes on develop and a test pins it, naming the commit that fixed it; or the issue is closed as by design, naming the function or ADR.


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-23

Supervisor decision (2026-11-23): (b). The rule asserts go in as a new step after throws inference.

Why:

The rule expression was already type-checked as part of the struct. The new step inserts a checked expression and re-checks only what it inserted. It does not run the checker again on the method.

No amendment to ADR-369 is needed. A call that may fail is a point where the method can throw, and ADR-369 D2 already says the rule holds at each throw. Checking before such a call is D2 applied, not narrowed. The rule may still be broken between such points. In the swap_last probe the check firing before fail(n) is the intended behaviour: the method has to restore slots before the call that may fail, or make that call first. The test for #2518 should show both orders.

Relabelled ready, lane solver. Building this unblocks “A type whose mut self method throws keeps its rule as a fact” (#2518).


Generated by Claude Code

Back to Open Issues