-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[WIP] Warn unused unused annotation #10241
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
Conversation
ha,
and the code says
|
fc4d104
to
240ada0
Compare
240ada0
to
fc934ce
Compare
class C { | ||
def n: Int = 42 | ||
def f(@unused i: Int) = n + 1 | ||
def g(@unused i: Int) = i + 1 // unused unused |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused unused doesn't seem to be reported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to workaround the spurious report for ChromeTrace.EventType
, so I put in a version trip switch.
That is also why I fixed the ordering of ScalaVersion
so that 2.13.11-development < 2.13.11
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the problem of the unused diagnostic not seeing trees of constant values made me want to address the few well-known limitations with the unused checks for 2.13.11, depending perhaps on when it is scheduled.
if (sym != null && sym.pos.isDefined) | ||
sym.getAnnotation(UnusedClass).foreach { annot => | ||
if (!runReporting.suppressionExists(annot.pos)) | ||
runReporting.addSuppression(Suppression(annot.pos, List(MessageFilter.Category(WarningCategory.Unused)), sym.pos.start, sym.pos.end, synthetic = true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how reliable it is to use sym.pos
here...
➜ sandbox qs -Wunused
Welcome to Scala 2.13.11-20221222-071937-84bf5ca (OpenJDK 64-Bit Server VM, Java 17.0.1).
Type in expressions for evaluation. Or try :help.
scala> object t { @annotation.unused private var x = 2 }
java.lang.UnsupportedOperationException: Position.point on NoPosition
at scala.reflect.internal.util.Position.fail(Position.scala:24)
See rangeFinder
in Typers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had thrown in sym.pos.isDefined
for what I thought was good measure.
def GEN_== (other: Tree, kind: ClassSymbol) = fn(target, getMember(kind, nme.EQ), other) | ||
@unused("avoid warning for multiple parameters") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was due to an early version of multiarg infix that warned for this name, but it doesn't seem to warn now.
Fixes scala/bug#11631