Skip to content

false-positive "unused import" warning #21525

Closed
@xuwei-k

Description

@xuwei-k

Compiler version

  • 3.6.0-RC1-bin-20240828-5e83606-NIGHTLY
  • 3.5.1-RC2
  • 3.5.0
  • 3.4.3
  • 3.3.3

Minimized example

build.sbt

scalaVersion := "3.5.1-RC2"

scalacOptions += "-Wunused:imports"

A.scala

import scala.reflect.TypeTest

trait A {
  type B
  type C <: B

  given instance: TypeTest[B, C]
}

def f(a: A, b: a.B): Boolean = {
  import a.C
  b match {
    case _: C =>
      true
    case _ =>
      false
  }
}

Output Error/Warning message

[warn] -- [E198] Unused Symbol Warning: false-unused-import-warn-example-project/A.scala:11:11 
[warn] 11 |  import a.C
[warn]    |           ^
[warn]    |           unused import

Why this Error/Warning was not helpful

a.C is not unused

Suggested improvement

don't warn

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions