Skip to content

De-anonymize patvar in given pattern #23121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented May 8, 2025

Fixes #23119

A given pattern in a for comprehension results in a fresh val in the body of the mapping function, but is not correlated with patvars.

This commit gives the given its usual given name (in makeIdPat) so that the unused check can check it.

A subsequent pattern var is named when typechecked, which resulted in the warning.

The fix adds the PatternVar attachment in makeIdPat and also fixes the tree pos, so that it corresponds to the position of the pat var in the elaboration of the for (that is, the position of the given T tree).

The unused check can now detect the patvar using the attachment and use the tree pos (instead of the bind name pos).

Adds some mild refactoring to name subexpressions and reduce line lengths.

@som-snytt som-snytt force-pushed the issue/23119-for-given branch from def4dd7 to 4d0f402 Compare May 9, 2025 06:19
@som-snytt som-snytt changed the title Detect anonymized patvar in given pattern De-anonymize patvar in given pattern May 9, 2025
@som-snytt
Copy link
Contributor Author

The analysis relies on ignoring derived names and also correlating pattern vars by position.

The existing artifact received a "fresh" name and a zero-extent synthetic position.

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.

false positive warning
1 participant