Skip to content

False unused import warnings when importing "given" #25227

@jrlemieux

Description

@jrlemieux

Compiler version

3.8.1

Minimized code

See attached zip file, it contains a minimal sbt project.

You can run the test script with "./run.sh". This script changes the scala version in build.sbt and then calls "sbt clean compile". This is to demonstrate that the bug does not happen in 3.7.4 but does happen in 3.8.1.

This code compiles with the strict equality compiler option, with Java 25.

Output


$ ./run.sh 

Compiling with Scala 3.7.4

[info] welcome to sbt 1.12.2 (Ubuntu Java 25.0.2)
[info] ...
[info] compiling 2 Scala sources to /home/jacques/Documents/projects/given/target/scala-3.7.4/classes ...
[success] Total time: 1 s, completed 9 févr. 2026, 22:33:33

Compiling with Scala 3.8.1

[info] welcome to sbt 1.12.2 (Ubuntu Java 25.0.2)
[info] ...
[info] compiling 2 Scala sources to /home/jacques/Documents/projects/given/target/scala-3.8.1/classes ...
[warn] -- [E198] Unused Symbol Warning: /home/jacques/Documents/projects/given/src/main/scala/cc/lemieux/Test.scala:3:25 
[warn] 3 |import cc.lemieux.givens.given
[warn]   |                         ^^^^^
[warn]   |                         unused import
[warn] one warning found
[success] Total time: 2 s, completed 9 févr. 2026, 22:33:37

Expectation

This warning should not be emitted, as the import is required for the code to compile.

Strangely, when the two commented statements are uncommented, the code compiles without warning even with 3.8.1.

It is an annoying bug because I can't optimize imports anymore in IntelliJ, as it will delete all useless imports reported by the Scala compiler.

Many thanks.

This is standalone code that replicates the behavior of the code in the zip file:

object Givens:

  given CanEqual[Any, Null] = CanEqual.derived
  given CanEqual[Null, Any] = CanEqual.derived

import Givens.given

object Test:

  // No warning is emitted when these two lines are uncommented.
  // val value: Any = 0 
  // value == null

  def m(value: Any): Boolean =
    value match
      case null => true

given.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions