Skip to content

The verdict walks from every law, whichever file fills it, so an unsafe fill in an imported file is listed - #1033

Merged
nicolas-abril merged 1 commit into
bendlang:mainfrom
costamatheus97:fix-1001-law-verdict
Sep 24, 2026
Merged

nicolas-abril merged 1 commit into
bendlang:mainfrom
costamatheus97:fix-1001-law-verdict

Conversation

@costamatheus97

Copy link
Copy Markdown
Contributor

Fixes #1001.

Why

Since f1d23d3 (#848), cli_report walks the references of the file under check only: book.order.slice(n0). A law is declared in one file but can be filled in another. In the issue's repro, Helper.bend fills LAWS.false_law with an @unsafe self-call and PROOF.bend only imports Helper. The fill is pushed into Helper's part of book.order, and the root never names the law, so the walk never reaches it. bend PROOF.bend printed a clean All terms check. (exit 0), and the false law then proved every other law with no further unsafe.

The fix

One change in bend2/main.ts (cli_report): the walk's roots are the file's own entries plus every law outside Base.

A law is identified by the order, not by its name. book.order holds a law's key twice: once at its declaration and once at its fill. book_valid reads the order the same way (the first event checks the law's type, the last defines it). A def or type is pushed once, and template instances stay outside the order. So:

The fix adds 74 tokens to main.ts (9616 → 9690, cap 10000). bend.ts is untouched.

repro before after
issue repro 1 (fill in Helper) All terms check. - LAWS.false_law
issue repro 2 (succ_is_id derived in Helper) All terms check. - LAWS.false_law, - LAWS.succ_is_id
fill written in PROOF.bend - LAWS.false_law same
derivation in PROOF.bend, fill in Helper - boom, - LAWS.succ_is_id adds - LAWS.false_law, which the old listing omitted though it holds only by the unsafe fill

What stays the same

Tests

The four root tests are in tests/import/. The modules they import are in tests/import/unsafe-law/, so the gate doesn't read them as tests.

  • unsafe_law_fill: the issue's repro 1. The unsafe fill is in an imported module, and the verdict lists the law.
  • unsafe_law_derived: the issue's repro 2. A second law is proved from the unsafe one with no @unsafe of its own. Both laws are listed; the helper boom is not.
  • unsafe_law_unused: a law filled safely beside an @unsafe def that nothing names. The verdict stays All terms check.
  • unsafe_law_own: the unsafe fill is in the file under check. The output is the same as on main.

Validation

  • Check and interpretation of every test. These ran locally through bend main.bend --checkup over all tests, with each section compared to its #| lines. That is the gate's check and interp probes; the C and JS lanes did not run. tests/io/tcp_send_slow_peer is left out, as the gates leave it out.
    • On main with the new tests added: 1442 / 1444. The two failures are unsafe_law_fill and unsafe_law_derived, which print All terms check..
    • With the fix: 1444 / 1444.
    • Every other test's output is byte-identical before and after.
  • Demos: every demos/*/*.bend prints the same --check-only output on main and with the fix. That covers the ten PROOF/LAWS pairs, app_slash_boss_3d (which imports bend3d.bend) and the netcode files. No bench imports a local module.
  • Repository gate: gates/repo.ts passed, 46 / 46.
  • Not run: the cluster test gate and the perf and ping gates. No compile lanes are affected: the note goes to stderr, and the gate reads a build's output only when the build fails.

…fe fill in an imported file is listed (bendlang#1001)

Since bendlang#848, cli_report walked only the entries of the file under check
(book.order from n0). A law is declared in one file and may be filled in
another: a fill in a module PROOF.bend imports (Helper.bend filling
LAWS.false_law with an @unsafe self-call) sat outside that range, the root
never names the law, and `bend PROOF.bend` printed a clean "All terms
check." while the false law proved every other law with no further unsafe.

The walk's roots are now the file's own entries plus every law outside
Base. A law is the key book.order holds twice (its declaration, then its
fill; book_valid reads the order the same way), so no name or namespace
picks it: a file that registers keys under LAWS. (bendlang#1002) can add laws to
the walk, never hide one, and an unfilled law still fails as a TODO first.
The rule matches the TODO check, which already makes every open law in the
book the verdict's business wherever it is declared. The root's entries
come first, so a listing whose fills are all in the root is unchanged.

Importing still does not contaminate: an @unsafe def that neither the
file nor any law names stays silent. Exit codes do not change (bendlang#776, bendlang#805).

Tests (tests/import, modules in unsafe-law/): unsafe_law_fill, the fill in
an imported file, is listed; unsafe_law_derived, a law proved from the
unsafe one, lists both laws and not the helper; unsafe_law_unused, a safe
fill beside an unused @unsafe def, stays clean; unsafe_law_own, the fill
in the file under check, prints what it printed before.

@nicolas-abril nicolas-abril left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is right. Checked on main (ac0ddb7b) with this branch merged:

  • The issue's repro prints All terms check. on main and lists LAWS.false_law here; unsafe_law_fill and unsafe_law_derived fail on main and pass here, unsafe_law_unused and unsafe_law_own pass on both.
  • The order argument holds: parse_def fills a law only while it is unfilled and sends every other def through parse_fresh, so a key is ordered at most twice, and only as a law's declaration and fill. A law filled by a foreign body is refused by the checker, so that route stays closed too.
  • The gate's check/interp pass over every test: the 1441 existing sections are byte-identical to main, and all 1445 match their #| lines. All 50 demo files give the same --check-only output, and bun gates/repo.ts passes 46/46.

Note: this review was written by an AI after it tested the PR for me and I reviewed the findings. If anything here is wrong, reply and I will review it myself.

@nicolas-abril
nicolas-abril merged commit b7ebee9 into bendlang:main Sep 24, 2026
@Lorenzobattistela Lorenzobattistela mentioned this pull request Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One @unsafe law fill in a file PROOF.bend imports silently proves every law: bend PROOF.bend prints a clean "All terms check." (regression from #848)

2 participants