Fix 2.13.15-only false positives with -Wunused:patvars
#10870
Merged
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 false positives from
-Wunused:patvars
in the presence of filters (if
) — this was scala/bug#13041.Note that
-Wunused:patvars
is part of-Wunused
but is not enabled by-Xlint
. With this fix, interested users may wish to make a fresh attempt to add-Wunused:patvars
to their builds.The now-correct position information may also aid tooling, as seen in scala/bug#13037 .
Followup to #10812, which (in 2.13.15) expanded unused checking into this area.
Fixes scala/bug#13041
Fixes scala/bug#13037
Implementation notes
Summary: Track patvars by position (and correct span of guard closure)
The scheme of linking duplicated patvar trees via attachments is brittle because links are stale after duplication; in particular, they point to old trees which may not be typechecked, so symbols are not recoverable.
Instead, just identify associated trees by position: duplicates have a focused position and the "original" has its opaque range.
Fix range of guard closure in TreeGen.mkFor to include parameter. (In the previous scheme, the pattern and its duplicate were swapped to build the "links", but now have been swapped back again, so that bug is nullified.)
Some mild refactoring of position validation for readability.