Closed bjaglin closed 2 months ago
Thanks for the report and for using -Wunused
!
This is a feature, never to warn on the "canonical pattern".
It's mentioned in the comment at https://github.com/scala/scala/pull/10812
but I don't see where lrytz proposed it. Possibly, the idea was inherited from -Xlint:pattern-shadow
.
The experience in the scala/scala code base was that warning on case Apply(fun, args)
for these lints was too noisy.
The previous workaround was case Apply(fun @ _, args @ _)
to mean that the var names are documentary, but that is too verbose to be useful. That was a workaround for lacking named args in patterns.
So for warning, the idiom works like case x: Apply => import x.*
if the import did not warn as unused.
A -strict
option was not proposed because there are too many knobs, and the goal was the happy medium that errs on the side of false negative. A 3rd party lint could provide fine-grained config.
Oh, thanks! Do you know by any chance if there is a plan to forward-port this change to Scala 3 for consistency? I guess not - I couldn't find any related ticket.
It seems that 2.13.15 no longer reports unused pattern vars when they have the same name as the attributes.
Reproduction steps
Problem
Actual
No warning
Expected
Warnings like in 2.13.14