Skip to content

unused annotation does not silence warning in given using with shorthand #23033

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

Open
eejbyfeldt opened this issue Apr 23, 2025 · 3 comments · May be fixed by #23037
Open

unused annotation does not silence warning in given using with shorthand #23033

eejbyfeldt opened this issue Apr 23, 2025 · 3 comments · May be fixed by #23037
Assignees
Labels
area:annotations area:implicits related to implicits area:linting Linting warnings enabled with -W or -Xlint itype:bug regression This worked in a previous version but doesn't anymore

Comments

@eejbyfeldt
Copy link

Compiler version

3.7.0-RC3

Minimized code

import scala.util.NotGiven
import scala.annotation.unused

object Test {
  given [T](using @unused ev: NotGiven[T <:< Int]): AnyRef with {}
}

Output

Compiled using -Wunused:all

-- [E198] Unused Symbol Warning: unused_notgiven_annotation.scala:5:26 -----------------------
5 |  given [T](using @unused ev: NotGiven[T <:< Int]): AnyRef with {}
  |                          ^^
  |                          unused implicit parameter
1 warning found

Expectation

@unused should silence the warning as it does in other cases.

For example changing the code to

import scala.util.NotGiven
import scala.annotation.unused

object Test {
  given [T](using @unused ev: NotGiven[T <:< Int]): AnyRef = new AnyRef {}
}

works as expected.

@eejbyfeldt eejbyfeldt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 23, 2025
@eejbyfeldt
Copy link
Author

If #22969 get fixed the test case might need to be changed.

@som-snytt
Copy link
Contributor

som-snytt commented Apr 23, 2025

Perhaps the annotation winds up on the wrong element in the desugaring.

    given class given_AnyRef[T >: Nothing <: Any](using
      ev: scala.util.NotGiven[<:<[T, Int]]) extends AnyRef() {
      T
      @unused protected given val ev: scala.util.NotGiven[T <:< Int]
    }
    final given def given_AnyRef[T >: Nothing <: Any](using
      @unused ev: scala.util.NotGiven[<:<[T, Int]]): Test.given_AnyRef[T] =
      new Test.given_AnyRef[T](using ev)()

or it is dropped in posttyper.

It's time to revisit this condition:
https://github.com/scala/scala3/blame/main/compiler/src/dotty/tools/dotc/transform/PostTyper.scala#L249

@som-snytt som-snytt linked a pull request Apr 23, 2025 that will close this issue
@Gedochao Gedochao added area:annotations area:implicits related to implicits area:linting Linting warnings enabled with -W or -Xlint regression This worked in a previous version but doesn't anymore stat:needs bisection Need to use nightly builds and git bisect to find out the commit where this issue was introduced and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 24, 2025
@Gedochao
Copy link
Contributor

Last good release: 3.7.0-RC1-bin-20250127-89c20f8-NIGHTLY
First bad release: 3.7.0-RC1-bin-20250128-9cb97ec-NIGHTLY
c65d45d is the first bad commit (#20894)

@Gedochao Gedochao removed the stat:needs bisection Need to use nightly builds and git bisect to find out the commit where this issue was introduced label Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:annotations area:implicits related to implicits area:linting Linting warnings enabled with -W or -Xlint itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants