Skip to content
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

Suppress spurious Suppression #22383

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Jan 15, 2025

Guard against multiple registrations of nowarn on related elements.

Fixes #18341

@som-snytt
Copy link
Contributor Author

som-snytt commented Jan 16, 2025

By making it a case class so toString is useful, I can tell that not all the suppressions were the same. Here it's visible that end is different in the second suppression, so discarding it is bad.

ADD Suppression(tests/warn/i18341.scala:<296..303>,List(Any),296,296,false)

ADD Suppression(tests/warn/i18341.scala:<296..303>,List(Any),296,446,false)

In fact the duplication is because it sticks to everything:

  class B(@nowarn() useless: Int) extends Object() {
    @nowarn() private[this] val useless: Int
  }
  class C(@nowarn("msg=unused") useless: Int) extends Object() {
    @nowarn("msg=unused") private[this] val useless: Int
  }
  class D(useless: Int) extends Object() {
    private[this] val useless: Int
  }
  class E(@nowarn() useful: Int) extends Object() {
    @nowarn() private[this] val useful: Int
    def e: Int = E.this.useful.*(10)
  }
  class X() extends Object() {
    def extensionInCompanion: String = ???
  }
  @nowarn() final lazy module val X: X = new X()
  @nowarn() final module class X() extends Object() { this: X.type =>
    implicit def companionConversion(x: X): B = ???
    extension (x: X) def extensionInCompanion: String = ???
  }

Does this make the annotation useless? Well, check unused does say that a param is used iff its param accessor is used. Both should warn or neither; similarly for modules in whatever you call their dual nature. Normally, the "duplicate" warning would be ignored at the same position, assuming the message text also aligns.

But that is nonsense. The sensible way is to ignore duplicate nowarns with equal (start, end) and also of zero extent.

@som-snytt som-snytt marked this pull request as ready for review January 16, 2025 01:21
@som-snytt som-snytt changed the title Add Suppression only once Suppress spurious Suppression Jan 16, 2025
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.

-Wunused:nowarn falsely reports that an annotation does not suppress any warnings
1 participant