scala / scala3

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

Unused import falsely reported when used in named argument #18313

Open 2m opened 1 year ago

2m commented 1 year ago

Compiler version

3.3.0 and 3.3.1-RC4

Minimized code

//> using scala "3.3.1-RC4"
//> using options "-Wunused:all"

import scala.deriving.Mirror

case class Test(i: Int, d: Double)
case class Decoder(d: Product => Test)

// OK, no warning returned
// val d = Decoder(summon[Mirror.Of[Test]].fromProduct)

// returns warning:
// [warn] unused import
// [warn] import scala.deriving.Mirror
val d = Decoder(d = summon[Mirror.Of[Test]].fromProduct)

Output

-- Warning: i18313.scala:4:22 -----------------------------------
4 |import scala.deriving.Mirror
  |                      ^^^^^^
  |                      unused import

Expected

No warnings

som-snytt commented 3 days ago

Subtly enough, uncommenting the first val makes the warning go away. Oh obviously, that's because it sees the usage.

A NamedArg is an "early tree" that requires special handling.

Confirmed broken on 3.5.1 and fixed by the linked PR.

import scala.deriving.Mirror

case class Test(i: Int, d: Double)
case class Decoder(d: Product => Test)

// OK, no warning returned
// val ok = Decoder(summon[Mirror.Of[Test]].fromProduct)
//
// returns warning:
// [warn] unused import
// [warn] import scala.deriving.Mirror
val d = Decoder(d = summon[Mirror.Of[Test]].fromProduct)