Skip to content

A fallback past a type's last constructor goes to --verdict as \{}, as bend2 skips it, so a ~ argument or a type that has one checks (#1204) - #1246

Merged
nicolas-abril merged 1 commit into
bendlang:mainfrom
nicolas-abril:closed-tmpl-args
Oct 1, 2026

Conversation

@nicolas-abril

@nicolas-abril nicolas-abril commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1204.

What #1204 comes down to

A ~ argument with a caller's variable in a fallback past the last constructor, like \{Unit: 0n; x}, passes the closed-argument guard. That's because the checker skips dead code ("The checker skips dead code" in WONTFIX.txt). Two callers whose arguments differ only there, g(x: Nat) and h(x: Bool), then share one instance. That is harmless: the interpreter, JS and C all print the right value, because the dead arm never runs.

The real bug is --verdict. It reports a mismatch on these programs, and also on a closed argument like \{Unit: 3n; 0n}. It has nothing to do with templates either: the same dead fallback inside a type fails the same way.

The cause

bend2's checked terms already hold \{} where the checker skipped a dead default (check-mat), and the elaborator reads those. But it elaborates some terms bare, typing them itself:

  • terms inside types;
  • ~ arguments, which safe_book reads back from book.tmps.

In those, swi elaborated the written default, couldn't type it, and dropped the def ("an application with no known head type").

The change

swi takes a default past the last constructor as \{}, the same rule as check-mat (rem.length === 1 && tm.m.$ !== "Mat"). Like check-mat, it tests the default's raw tag, so an annotated match there ({\{Unit: 1n} : Unit -> Nat}) is a dead fallback too, and only a bare match continues the chain. That's two lines in safe.ts, and bend.ts is untouched.

Checks

  • New tests, which print the same value in the interpreter, JS and C:

    Test Prints --verdict on main --verdict here
    tests/proof/dead_fallback_type: a dead fallback in a type, no template, written plainly and as an annotated match 3n SOME PROOFS FAIL ALL PROOFS CHECK
    tests/comptime/dead_arm_shared: def_inst reuses template specializations across unrelated functions due to un-scoped term_key collisions #1204's two callers 0n SOME PROOFS FAIL ALL PROOFS CHECK

    gates/safe.ts would report both as false rejects on main.

  • No change elsewhere: for all 1606 .bend files under tests/, bench/ and demos/, the --check-only output, emitted .c, .js, .bendtt and every log are identical to main (1606 files, 8995 outputs compared). No existing program had a dead fallback in a bare term.

  • Gates: tsc gives the same 12 errors as main. gates/repo.ts passes, 50 / 50. safe.ts goes from 20,244 to 20,280 ttok.

  • Not run: the cluster gates, gates/safe.ts included.

🤖 Generated with Claude Code

@nicolas-abril nicolas-abril changed the title A ~ argument that reads a caller's variable in an arm no value reaches is open, so two callers no longer share one instance (#1204) A ~ argument that reads a caller's variable in any arm is open, by the name it reads, so two callers no longer share one instance (#1204) Oct 1, 2026
@nicolas-abril nicolas-abril changed the title A ~ argument that reads a caller's variable in any arm is open, by the name it reads, so two callers no longer share one instance (#1204) A fallback past a type's last constructor goes to --verdict as \{}, as bend2 skips it, so a ~ argument or a type that has one checks (#1204) Oct 1, 2026
…s bend2 skips it, so a ~ argument or a type that has one checks (bendlang#1204)

bend2 skips a default past the last constructor (dead code, WONTFIX), and
its checked terms hold \{} there. A bare term the elaborator types itself,
a term in a type or a ~ argument read back from book.tmps, kept the
written default, which the elaborator could not type: the def went out of
scope ("an application with no known head type") and --verdict reported a
mismatch where bend2 checked. swi now takes that default as \{}.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

def_inst reuses template specializations across unrelated functions due to un-scoped term_key collisions

1 participant