Closed
Description
Compiler version
3.3.1
Minimized code
//> using scala "3.3.1"
//> using option "-Wunused:imports"
import scala.compiletime.*
import scala.deriving.*
trait Foo
trait HasFoo[A]:
/** true if A contains a Foo */
val hasFoo: Boolean
// given instances that need to be imported to be in scope
object HasFooInstances:
given defaultHasFoo[A]: HasFoo[A] with
val hasFoo: Boolean = false
given HasFoo[Foo] with
val hasFoo: Boolean = true
object HasFooDeriving:
inline private def tupleHasFoo[T <: Tuple]: Boolean =
inline erasedValue[T] match
case _: EmptyTuple =>
false
case _: (t *: ts) =>
summonInline[HasFoo[t]].hasFoo || tupleHasFoo[ts]
inline def deriveHasFoo[T](using p: Mirror.ProductOf[T]): HasFoo[T] =
// falsely reported as unused even though it has influence on this code
import HasFooInstances.given
val pHasFoo = tupleHasFoo[p.MirroredElemTypes]
new HasFoo[T]:
val hasFoo: Boolean = pHasFoo
Output
[warn] ./HasFoo.scala:31:28
[warn] unused import
[warn] import HasFooInstances.given
[warn] ^^^^^
Note:
- No warning is emitted if
deriveHasFoo
is called in the same file - A warning still is emitted if
deriveHasFoo
is called in a different file
Expectation
No warning is emitted.