Skip to content

fix: preserve TermInfo for do-match discriminant variables#12666

Merged
sgraf812 merged 1 commit intomasterfrom
sg/fix-do-match-info
Feb 24, 2026
Merged

fix: preserve TermInfo for do-match discriminant variables#12666
sgraf812 merged 1 commit intomasterfrom
sg/fix-do-match-info

Conversation

@sgraf812
Copy link
Copy Markdown
Contributor

@sgraf812 sgraf812 commented Feb 23, 2026

This PR fixes spurious unused variable warnings for variables used in non-atomic match discriminants in do notation. For example, in match Json.parse s >>= fromJson? with, the variable s would be reported as unused.

The root cause is that expandNonAtomicDiscrs? eagerly elaborates the discriminant via Term.elabTerm, which creates TermInfo for variable references. The result is then passed to elabDoElem for further elaboration. When the match elaboration is postponed (e.g. because the discriminant type contains an mvar from fromJson?), the result is a postponed synthetic mvar. The withTermInfoContext' wrapper in elabDoElemFns checks isTacticOrPostponedHole? on this result, detects a postponed mvar, and replaces the info subtree with a hole node — discarding all the TermInfo that was accumulated during discriminant elaboration.

The fix applies mkSaveInfoAnnotation to the result, which prevents isTacticOrPostponedHole? from recognizing it as a hole. This is the same mechanism that elabLetMVar uses to preserve info trees when the body is a metavariable.

🤖 Generated with Claude Code

@sgraf812 sgraf812 added the changelog-language Language features and metaprograms label Feb 23, 2026
@sgraf812 sgraf812 force-pushed the sg/fix-do-match-info branch from e7ab6d5 to 7750211 Compare February 23, 2026 23:26
@sgraf812 sgraf812 enabled auto-merge February 23, 2026 23:28
@sgraf812 sgraf812 disabled auto-merge February 23, 2026 23:28
@sgraf812 sgraf812 force-pushed the sg/fix-do-match-info branch from 7750211 to af596e9 Compare February 23, 2026 23:29
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>
@sgraf812 sgraf812 force-pushed the sg/fix-do-match-info branch from af596e9 to 0a885cb Compare February 23, 2026 23:31
@sgraf812 sgraf812 enabled auto-merge February 23, 2026 23:31
@sgraf812 sgraf812 added this pull request to the merge queue Feb 23, 2026
Merged via the queue into master with commit cdbed91 Feb 24, 2026
15 checks passed
@sgraf812 sgraf812 deleted the sg/fix-do-match-info branch February 24, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-language Language features and metaprograms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant