Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

som-snytt
Copy link
Contributor

@scala-jenkins scala-jenkins added this to the 2.13.11 milestone Dec 18, 2022
@som-snytt
Copy link
Contributor Author

ha,

[error] /home/jenkins/workspace/scala-2.13.x-validate-main/src/reflect/scala/reflect/internal/util/ChromeTrace.scala:24:18: spurious @unused
[error]   private object EventType {
[error]                  ^
[error] one error found

and the code says

  @annotation.unused // spurious
  private object EventType {

@som-snytt som-snytt force-pushed the issue/11631-lint-unused branch from fc4d104 to 240ada0 Compare January 1, 2023 05:22
@som-snytt som-snytt force-pushed the issue/11631-lint-unused branch from 240ada0 to fc934ce Compare January 1, 2023 07:19
class C {
def n: Int = 42
def f(@unused i: Int) = n + 1
def g(@unused i: Int) = i + 1 // unused unused
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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))
Copy link
Member

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

Copy link
Contributor Author

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")
Copy link
Contributor Author

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.

@som-snytt som-snytt marked this pull request as draft January 21, 2023 15:29
@SethTisue SethTisue modified the milestones: 2.13.11, 2.13.12 Feb 28, 2023
@som-snytt som-snytt closed this Jun 5, 2023
@SethTisue SethTisue removed this from the 2.13.12 milestone Jun 10, 2023
@som-snytt som-snytt changed the title Warn unused unused annotation [WIP] Warn unused unused annotation Jan 27, 2024
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.

Verify unused
4 participants