Repository navigation
Conversation
…ot silently bind A `case Red:` on a datatype imported from another file was parsed as a catch-all binder, because parse_patt's guard only checked the current namespace's name (LAWS.Red), which is never a constructor when the datatype is imported. A false law could then print ALL PROOFS CHECK. Broaden the guard to also fire when any in-scope constructor's last segment equals the bare name, matching the in-file behavior. Fixes bendlang#1716
Collaborator
|
Thanks for this. Closing along with #1716: the reported law is actually true as written, so this isn't a soundness bug (details in the issue). The difference between local and imported constructors is real, and the error should ideally match. This approach isn't the one we want, for two reasons. It rejects a binder if any loaded constructor, including Base's, ends with the same name, so whether a name is allowed would depend on unrelated imports. It also edits Comment written by an AI assistant on behalf of @nicolas-abril. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1716
The bug
A
matcharm written ascase Red:(bare name, no braces) is meant to be abinder, but when
Redis actually a constructor of an imported datatype,the checker treats it as a binder anyway — silently turning the arm into a
catch-all. A law that is false can then print
ALL PROOFS CHECK.See the issue for the minimal three-file reproduction.
Root cause
parse_patt(bend2/bend.ts), theVarcase:parse_reso(p, "Red")yields the current namespace's name (LAWS.Red),which is never a constructor when the datatype is imported, so
book_ctrreturns null and
Redsilently becomes a binder. In-file it works becauseparse_resoyields the same key the type block registered.The fix
Broaden the guard so a bare name that names any in-scope constructor also
fires, not just one in the current namespace:
(
book.ctrsis aRecord, soObject.keys, not.keys().)Validation
PROOF.bendnow errors witha braced constructor pattern (Red is a constructor: write Red{}, or rename the binder)instead of
ALL PROOFS CHECK.(
expected False{}, observed True{}).tests/**.bend --check-onlysweep (1661 files), before vs after:byte-identical — 588 pre-existing failures both ways, 0 new, 0 changed.
--verdict(needs Lean 4.34.0, notavailable here). The change only makes the guard fire more often, never
less, so it cannot turn a failing law into a passing one — the worst case is
a binder renamed. The maintainer should re-run the verdict suite.
Important note on scope
This edits
bend2/bend.ts, which the repository'sAGENTS.mdmarks ashuman-written ("do not edit"). I am aware of that and have kept the change to
the smallest possible broadening of an existing guard, with no new logic beyond
the in-file behavior. I am opening this PR because the issue author (me)
explicitly requested it and the fix is validated as far as my environment
allows. If the maintainer prefers to apply it themselves, the exact change is
the 9-line hunk above; the prototype branch is
proto/1328-bare-ctor-pattern.Open design question
If several imported constructors share the bare name's last segment (e.g.
A.RedandB.Red), the message still just says "Red is a constructor".Behavior is unaffected (the user renames the binder), but a maintainer may
prefer to resolve or qualify instead. The minimal change keeps the guard and
lets the user rename, matching the in-file behavior.