Issue #2832: An impl Ord’s compare is emitted as a private inherent fn, so a caller outside the declaring crate fails at rustc (NK1343)

Open and answer this issue on GitHub.

wip, bugs · opened 2026-11-23 · updated 2026-12-01 · 2 comments

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

Found

use std::bigint / fn main() throws { let a = bigint::BigInt::of(1); println(a.compare(bigint::BigInt::of(2)) == Ordering::Less) } (scripts/probe.nika, target/fast/nikaia at HEAD) stops at NK1343 “Rustc output: method compare is private”, should print true (the checker accepts it; Part I Ord’s compare is callable): the emitter writes an impl Ord’s compare as a private inherent fn (bigint.rs impl BigInt { fn compare(&self, ..) }), so a caller outside the crate that declares the type cannot reach it; suspected crates/nikaia-std/src/compiler/emit_item.nika, the inherent twin of a trait impl’s method is emitted without pub (check: the same call on a type of a dependency package)

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-12-01

Brief queued: issue-2832


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

Issue #2832

Your work order is issue #2832, 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/2832/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-2832.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-12-01

Run: issue-2832, Result: done

Tokens: input 112, cache read 3349443, cache write 71621, output 20066 Cost: 1.69 USD, time 2 min 45 s, turns 56

Report

Result: done Files: crates/nikaia-std/src/bigint.nika crates/nikaia-std/src/bigint.rs crates/nikaia-std/src/compiler/emit_item.nika crates/nikaia-std/src/compiler/lowered.rs crates/nikaia-std/src/compiler/lowered/emit_item.rs crates/nikaia-std/src/compiler/lowered/ty.rs crates/nikaia-std/std.contracts crates/nikaia-std/src/lib.rs tests/compiler/tests/an_ord_compare_of_a_std_type_is_callable_from_a_program.nika tests/compiler/tests/an_ord_compare_of_a_std_type_is_callable_from_a_program.stdout Commit: emit: a public type’s impl Eq/Ord/Hash methods are pub, so a.compare(b) reaches them from another crate; BigInt::compare lends other Body: Probe use std::bigint / println(bigint::BigInt::of(1).compare(bigint::BigInt::of(2)) == Ordering::Less) gave NK1343 “method compare is private” at HEAD e5dfa83a1; now prints true (Part I, Ord: compare is callable). Two causes, both traced: (1) emit_item.nika’s Eq/Ord/Hash branch emitted the inherent twin without pub; it now passes emit_item_public_type as bridged, as the ADR-288 D25 bridge branch already does, so a pub type’s methods are pub (a dependency package’s impl Ord called as a.compare(lib::make(2)) failed the same way and now runs). (2) bigint.nika’s compare took other: BigInt by value while the emitter lends it (&BigInt); std.contracts has no column for a lent by-value parameter (the by_value comment in tests/it/contracts.rs, #2706), so a caller passed it by value (rustc mismatched types). It is now other: ref BigInt, like every other BigInt method, and its std.contracts entry matches. The lowered ty.rs CodeNames eq/hash became pub, so clippy::should_implement_trait joins the tools module’s allow list in lib.rs. Fixes: #2832 Pushed: local 05f71826db685e1a557d1239135b55daf2053402 Tests: new an_ord_compare_of_a_std_type_is_callable_from_a_program failed on $NIKAIA_OLD (NK1343) and passes –both-settings; tests/compiler filters impl_hash, a_declared_type_is_a_hash_key, ord_, eq_ green (26); it contracts::the_shipped_std_ledger_agrees_with_its_nikaia_sources green; lower-std fixpoint clean; clippy, fmt, pre-push green Gate: green Deviation: none Found: none Needs: none Changelog: An impl Ord’s compare (and impl Eq/impl Hash’s methods) of a public type can be called from another package or on std’s BigInt. Issue: complete Owner: none Comment: none Friction: none Disk freed: none (target/nikaia-project-tests 2.0G, / 9.8G free, no new entry over 100 MB) Reviewed: 3c52ba02103f741ec314b04485156c8305bd2c621efc28256fb012b50244f4f3 Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDutPTwP5Xj5HkGuidk

Debrief

  1. Most turns or time: the second cause. After the pub fix, the probe failed again with a rustc “mismatched types”. I had to find that std.contracts gives compare a by-value other while the emitter lends it, and that this ledger can’t record a lent by-value parameter. Two build cycles of about 10 minutes each.
  2. Looked up: where the Eq/Ord/Hash impl is emitted (emit_item.nika, the PartialOrd string) and how pub is decided (owner_bridged in emit_function.nika). Also that the bigint part of std.contracts is derived from bigint.nika and checked by contracts::the_shipped_std_ledger_agrees_with_its_nikaia_sources.
  3. Checks run: the probe on $NIKAIA_OLD, the cycle twice, the new test, the ledger-agreement test, four related test filters, clippy, fmt, pre-push. Wasted: the first new-binary test run, because I built before probing the argument-passing shape.
  4. Change that would save the most: a builder.md line: “after a visibility fix, run the probe once before anything else; it may only uncover the next rustc error”.
  5. What the issue lacked:
    • broke I7: it named the emitter only as suspected, and missed the second cause, the by-value compare in std.contracts.
    • knowledge: Lowering and lower-std | a std module in Nikaia that lends a by-value parameter needs ref in its source, because std.contracts has no by_value column (#2706).
  6. Traps the next builder will meet:
    • Fact: Lowering and lower-std | making a lowered tools method pub can trip clippy::should_implement_trait (eq, hash); it goes into the tools allow list in lib.rs.
    • Fact: Checker and views | std callers read std.contracts only, so a std .nika method's by-value parameter that the emitter lends is passed by value at the call (rustc mismatched types): write it as ref.
  7. Work area: Fact: none

Generated by Claude Code

Back to Open Issues