Skip to content

False negative unused import when there's a reference in macro-expanded code #24561

@kubukoz

Description

@kubukoz

Compiler version

3.7.4, 3.8.1-RC1-bin-20251127-fd2172d-NIGHTLY

Minimized code

  1. main.scala
//> using scala 3.nightly
//> using option -Wunused:all
import ext.Reader
import ext.NonEmptyList

@main def run = locally {
  macros.demo
}
  1. ext.scala
package ext

case class Reader[F[_], A, B]()

case class NonEmptyList()
  1. macros.scala
import ext.Reader
import scala.quoted.*

object macros {
  inline def demo: Unit = ${ demoImpl }

  def demoImpl(
    using Quotes
  ): Expr[Unit] =
    '{
      val r: Reader[Option, String, String] = ???
      ()
    }

}

Output

[warn] ./demo.scala:4:12
[warn] unused import
[warn] import ext.NonEmptyList
[warn]            ^^^^^^^^^^^^^

Expectation

An additional warning on import ext.Reader.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:lintingLinting warnings enabled with -W or -Xlintitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions