Fix false unused import warning for given CanEqual in pattern matching#25231
Fix false unused import warning for given CanEqual in pattern matching#25231Bbn08 wants to merge 1 commit intoscala:mainfrom
Conversation
|
There is a PR #25114 to move the lint after patter matcher to detect these comparisons. |
|
@som-snytt Thanks for pointing to #25114, I believe your fix should address this as well, since moving I had put together a smaller, targeted fix that adds That said, if your merged fix already covers this case fully, I'm happy to close my PR please let me know. Thanks for the great work on this! |
som-snytt
left a comment
There was a problem hiding this comment.
I confirmed it is fixed by the other PR, which is merged, but it would be nice to have this test without the code change!
e238a24 to
296a0ba
Compare
|
I've updated this PR to be test only the code changes to What this PR now contains:
I'm sorry if this change took more than the expected time had something going on in life. Thank you. |
dabde04 to
079bf8c
Compare
Problem
Fixes #25227
Under strict equality,
import Givens.given(providingCanEqual[Any, Null]) is falsely reported as unused when the given is consumed only by pattern matching (case null =>), even though removing it breaks compilation. The warning does not appear when the given is consumed by==/!=.Root Cause
CheckUnused.transformApplycorrectly resolvesCanEqualfor==/!=viaresolveScoped(caneq), marking the given import as used. However,transformMatchhad no equivalent logic for pattern matching against literal/null patterns, so the import was never marked as used.Fix
Added the same
resolveScoped(caneq)logic totransformMatchfor Literal patterns (including null). When a Match tree has a literal pattern, we constructCanEqual[SelectorType, PatternType]and callresolveScopedto mark any given import providing it as used.Testing
New test
tests/warn/i25227.scalawith both positive (used bycase null =>) and negative (genuinely unused) casesAll existing warn tests pass, including
unused-can-equal.scalaandi17762.scala