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

-Wunused gives warnings to values used in annotations #16877

Closed
markehammons opened this issue Feb 10, 2023 · 3 comments · Fixed by #16956
Closed

-Wunused gives warnings to values used in annotations #16877

markehammons opened this issue Feb 10, 2023 · 3 comments · Fixed by #16956
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@markehammons
Copy link

markehammons commented Feb 10, 2023

Compiler version

3.3.0-RC2

Minimized code

import org.openjdk.jmh.annotations.*, Mode.{SingleShotTime, Throughput}
import java.util.concurrent.TimeUnit

@State(Scope.Thread)
@BenchmarkMode(Array(Throughput, SingleShotTime))
@Fork(
  jvmArgsAppend = Array(
    "--enable-preview",
    "--enable-native-access=ALL-UNNAMED"
  )
)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
class Test

https://scastie.scala-lang.org/W9ZhbHhJTr2zjkBC5FwUXQ

Output

unused imports for singleshot time, throughput, and TimeUnit

Expectation

These are clearly used.

@markehammons markehammons added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 10, 2023
@jchyb jchyb added area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 10, 2023
@jchyb
Copy link
Contributor

jchyb commented Feb 10, 2023

Minimized:

import scala.collection.immutable.HashMap
import scala.annotation.StaticAnnotation

class ExampleAnnotation(val a: Object) extends StaticAnnotation

@ExampleAnnotation(new HashMap())
class Test

shows:

-- Warning: a.scala:1:34 -------------------------------------------------------
1 |import scala.collection.immutable.HashMap
  |                                  ^^^^^^^
  |                                  unused import

@jchyb jchyb added area:linting Linting warnings enabled with -W or -Xlint and removed area:reporting Error reporting including formatting, implicit suggestions, etc labels Feb 12, 2023
@kyri-petrou
Copy link

Not sure if related, but same issue occurs for imports used alongside the derives keyword. e.g.,

import io.circe.generic.semiauto.*
import io.circe.Codec

final case class Foo(foo: String) derives Codec.AsObject

szymon-rd added a commit that referenced this issue Feb 18, 2023
@szymon-rd  Fixes #16877 
- Traverse the tree of annotations
- Update test suits

The issue is that the annotation was registered but not traversed.
@carlosedp
Copy link

carlosedp commented Feb 24, 2023

I'm also seeing unused warning when using annotations on 3.3.0-RC3:

import zio.*
import zio.temporal.*
// import zio.temporal.{workflowInterface, workflowMethod} // same warning using like this

// This is our workflow interface
@workflowInterface
trait EchoWorkflow {

  @workflowMethod
  def echo(str: String): String
}
❯ ./mill hello.compile
Compiling /Users/cdepaula/repos/scala-playground/zio-temporal-hello/build.sc
[34/34] hello.compile
[info] compiling 5 Scala sources to /Users/cdepaula/repos/scala-playground/zio-temporal-hello/out/hello/compile.dest/classes ...
[error] -- Error: /Users/cdepaula/repos/scala-playground/zio-temporal-hello/shared/src/EchoWorkflow.scala:2:20
[error] 2 |import zio.temporal.*
[error]   |                    ^
[error]   |                    unused import
[error] one error found
1 targets failed
hello.compile Compilation failed

Same happens with no "*" imports for these annotations like comment in code above.

@Kordyjan Kordyjan modified the milestones: 3.3.1, 3.3.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants