scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

-Ywarn-unused:implicits reports unused implicit in override #12896

Closed rgugliel-da closed 8 months ago

rgugliel-da commented 8 months ago

Reproduction steps

Scala version: 2.13.12

Compiler flags:

lazy val root = (project in file("."))
  .settings(
    name := "sandbox",
    scalacOptions ++= Seq("-Ywarn-unused:implicits")
  )
trait Trait {
  def func()(implicit i: Long): Unit
}

class Impl extends Trait {
  override def func()(implicit i: Long): Unit = println("Impl")
}

Problem

On 2.13.12, the compiler unexpectedly warns:

[warn] /home/user/sandbox/src/main/scala/Trait.scala:8:32: parameter i in method func is never used
[warn]   override def func()(implicit i: Long): Unit = println("Impl")

On 2.13.11, the compiler does not output a warning.

The above code is a minimalistic example but this pattern occurs quite often in code, e.g., then the implicit is an execution context.

Other remarks:

  1. Adding a parameter to the method (e.g., func(j: Long)(implicit i: Long) make the warning disappear.
  2. Removing the () (i.e., def func(implicit i: Long) make the warning disappear.

Note that I don't want to use solution 2. because I use () to indicate that my method has side effects.

som-snytt commented 8 months ago

Thanks for the report, which duplicates https://github.com/scala/bug/issues/12876 which is already fixed.

rgugliel-da commented 8 months ago

Thanks for the prompt reply. I missed the other ticket, sorry.