Skip to content

A λ rebuilt as a match keeps its annotations on its own binders, so --verdict checks what bend2 checks (#1669) - #1670

Open
aaaxn wants to merge 3 commits into
bendlang:mainfrom
aaaxn:rebuild-binder-levels
Open

aaaxn wants to merge 3 commits into
bendlang:mainfrom
aaaxn:rebuild-binder-levels

Conversation

@aaaxn

@aaaxn aaaxn commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #1669. Depends on #1666, whose subst(t, d) the fix uses. Until #1666 merges, this PR's diff also shows its two commits. Only the last commit, 45716b3, is new here.

Cause

use(-f: P -> Nat) takes f erased, so bend2 lets the λ passed for it use its variable twice. rebuild in safe.ts turns that λ into a λ-match on the variable and calls the λ's body on each constructor, under a binder per field. bend2's annotations name a variable by the level bend2 checked it at, so they still name the variable's old level. With fields, that level now belongs to the first field, and the kernel rejects the term (expected: P). With no fields, no variable in scope has that level, and --verdict reports a free variable.

Fix

rebuild passes the λ through subst(x, s.d) before it calls the body, as #1666 does in eta. In the lowered form, an annotation names the body's binders as the body's own uses do, so the annotations move with the binders.

Checks

On #1666's head (fce97a9), Linux x86_64, kernel built from main's bendtt.lean with Lean 4.34.0:

Merge order

With #1657 as well, all three PRs apply cleanly and the tests above check, but safe.ts comes to 24,006 ttok, over its 24,000 cap. Whichever of #1657 and this PR lands second has to save 6 tokens.

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.

--verdict mismatch: a λ rebuilt as a match keeps its variable's old level in its annotations (Nat where P is expected)

1 participant