Make a type-annotated binder shadow a like-named constant#184
Open
kings-crown wants to merge 1 commit into
Open
Make a type-annotated binder shadow a like-named constant#184kings-crown wants to merge 1 commit into
kings-crown wants to merge 1 commit into
Conversation
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.
A bound variable may legitimately share its name with a constant, and
the binder should win within its scope. This already worked for
un-annotated varstructs via ignore_constant_varstruct, but broke as soon
as the binder carried a type annotation:
Cause: in typify's Absp branch the varstruct was typed first, and only
then was a resulting Constp rewritten back to a Varp. With an annotation
the constant-resolution clause unifies the constant's generic type
(bool) against the annotation (num) and raises before that post-hoc
rescue can run.
Fix: seed the varstruct's constant-named binders into venv before typing
it, so they take typify's "already a bound variable" clause rather than
being resolved to the like-named constant. This generalizes the old
rescue: it also covers type-annotated binders such as
\(Q1:num#num#num#num). ...and tuple varstructs. Only binder-positionconstant names are seeded, so free occurrences still resolve to the
constant. With ignore_constant_varstruct=false the previous behaviour is
preserved exactly.
Patch constructed with the help of (mostly) Claude Code.