scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.83k stars 1.05k forks source link

given CanEqual reported as unused even if required by strictEquality #21412

Closed marcopiii closed 1 month ago

marcopiii commented 1 month ago

Compiler version

    scalaVersion := "3.3.0",
    scalacOptions ++= List(
      "-language:strictEquality",
      "-Wunused:all",
      "-Xfatal-warnings",
      "-source:future"
    )

Minimized code

@main
def main(): Unit = {

  type DorS = Double | String

  val a: DorS = 1.0
  val b: DorS = "hello"

  given CanEqual[DorS, DorS] = CanEqual.derived

  println(a == b)

}

Output

[error] -- Error: .../main.scala:9:8 
[error]   |  given CanEqual[DorS, DorS] = CanEqual.derived
[error]   |        ^^^^^^^^^^^^^^^^^^^^^^^^
[error]   |        unused local definition

but if I remove it the compiler rightfully states that

Values of types DorS and DorS cannot be compared with == or !=

Expectation

I expect no warning since the given is used and needed

Gedochao commented 1 month ago

This has already been fixed in Next (3.4.0 and onwards), as well as backported to 3.3.4-RC1. For the LTS line, either test with the RC or wait for 3.3.4 to be out.

//> using options -language:strictEquality -Wunused:all -Xfatal-warnings -source:future
//> using scala 3.3.4-RC1 3.4.0 3.4.1 3.4.2 3.5.0
@main def main(): Unit = {
  type DorS = Double | String
  val a: DorS = 1.0
  val b: DorS = "hello"
  given CanEqual[DorS, DorS] = CanEqual.derived
  println(a == b)
}

Closing this, nothing to be done.