Skip to content

-Wunused gives false positives for destructuring tuple assignments within for #16926

Closed
@note

Description

@note

Compiler version

3.3.0-RC2

Minimized code

//> using scala "3.3.0-RC2"
//> using options "-Wunused:all"

@main
def hello(): Unit =
  for {
    i <- (0 to 10).toList
    (a, b) = "hello" -> "world"
  } yield println(s"$a $b")

Output

Compiling project (Scala 3.3.0-RC2, JVM)
[warn] ./unused-bug2.scala:8:6: unused local definition
[warn]     (a, b) = "hello" -> "world"
[warn]      ^
[warn] ./unused-bug2.scala:8:9: unused local definition
[warn]     (a, b) = "hello" -> "world"
[warn]         ^

Expectation

Neither a nor b being marked as unused

Other

Interestingly, it doesn't happen with "normal" (i.e. not contained in for) tuple destructuring. The following doesn't produce false positives:

//> using scala "3.3.0-RC2"
//> using options "-Wunused:all"

@main
def hello(): Unit =
  val (a, b) = "hello" -> "world"
  println(s"$a $b")

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions