scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

false positive of unused var when inside pattern match 2.13.15 #13046

Closed Zuchos closed 1 month ago

Zuchos commented 1 month ago

After bumping Scala to 2.13.15 with an unused warning, I'm getting a false positive warning. I extracted a synthetic case

Reproduction steps

Scala version: 2.13.15

object Test {
  def split(): Option[(Int, Int)] = ???
  def doIt(): Option[Int] = {
    Some((1, 2)).flatMap { case (_, _) =>
      for {
        (c, d) <- split()
        e       = c + d
      } yield {
        e
      }
    }
  }
}

Test.scala:9:9: pattern var e in value $anonfun is never used
[error]         e       = c + d
[error]         
Zuchos commented 1 month ago

Ok, looks like a duplicate of https://github.com/scala/bug/issues/13041 In particular, this comment proves that the filter is not the case https://github.com/scala/bug/issues/13041#issuecomment-2377958799

som-snytt commented 1 month ago

Thanks, I verified the example does not warn on head.