Issue #2491: fold_bound reads which lambdas run at most once from the once contract field, not a list of names

Open and answer this issue on GitHub.

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

Part of #973 After #973

What it is

fold_bound.nika decides which entry methods run their lambda at most once from a hard-coded list of names (in fn method: let once = name == "and_modify" || name == "or_insert_with" || name == "or_insert_with_key"). ADR-lambdas-1 D2 makes this a fact of each entry’s contract (once in std.contracts, added by #973). This part makes fold_bound read that field instead of the names, so the fact lives in one place.

To build

  1. crates/nikaia-std/src/compiler/fold_bound.nika method: the hard-coded once name list reads the contract field instead. The list today also names or_insert_with_key, which #973’s contract list does not; the builder checks whether or_insert_with_key exists in std.contracts and, if it does, reports it as a Found: line rather than dropping or adding it silently.

Done when

fold_bound.nika holds no list of method names for once-ness and reads the once contract field, with the tests that exercise fold_bound on or_insert_with / and_modify (for example tests/compiler/tests/a_btree_map_entry_or_insert_and_modify.nika) unchanged; the commit carries the Fixes line for this issue.

Files

crates/nikaia-std/src/compiler/fold_bound.nika (and its lowered output).

Split from #973 by Claude Code

Back to Open Issues