fix: preserve TermInfo for do-match discriminant variables#12666
Merged
fix: preserve TermInfo for do-match discriminant variables#12666
Conversation
e7ab6d5 to
7750211
Compare
7750211 to
af596e9
Compare
This PR fixes spurious unused variable warnings for variables used in non-atomic match discriminants in `do` notation. When `expandNonAtomicDiscrs?` eagerly elaborates discriminants (creating TermInfo for variable references), and the inner match elaboration is postponed, `withTermInfoContext'` in `elabDoElemFns` would detect the postponed mvar result and discard all info subtrees — including the TermInfo that marks discriminant variables as used. The fix wraps the result with `mkSaveInfoAnnotation` (the same mechanism used by `elabLetMVar`) to prevent the info subtrees from being discarded. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
af596e9 to
0a885cb
Compare
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.
This PR fixes spurious unused variable warnings for variables used in non-atomic match discriminants in
donotation. For example, inmatch Json.parse s >>= fromJson? with, the variableswould be reported as unused.The root cause is that
expandNonAtomicDiscrs?eagerly elaborates the discriminant viaTerm.elabTerm, which creates TermInfo for variable references. The result is then passed toelabDoElemfor further elaboration. When the match elaboration is postponed (e.g. because the discriminant type contains an mvar fromfromJson?), the result is a postponed synthetic mvar. ThewithTermInfoContext'wrapper inelabDoElemFnschecksisTacticOrPostponedHole?on this result, detects a postponed mvar, and replaces the info subtree with aholenode — discarding all the TermInfo that was accumulated during discriminant elaboration.The fix applies
mkSaveInfoAnnotationto the result, which preventsisTacticOrPostponedHole?from recognizing it as a hole. This is the same mechanism thatelabLetMVaruses to preserve info trees when the body is a metavariable.🤖 Generated with Claude Code