Skip to content

Scala 2.13.15: warn unused false positive when pattern matching on HOF parameter #13061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PiotrBosak opened this issue Nov 20, 2024 · 1 comment

Comments

@PiotrBosak
Copy link

PiotrBosak commented Nov 20, 2024

Reproduction steps

https://scastie.scala-lang.org/LI6ZuhHfS3CjvYepfhJjyw
Scala version: 2.13.15 with "-Ywarn-unused" flag
(Is the bug only in Scala 3.x? If so, report it at scala/scala3 instead.)

    List(("first", "second"))
      .map { case (_, _) =>
        for {
          a <- Some("a")
          b = a // b is not used warning
        } yield b
      }

Problem

When using a pattern match anonymous function in a HOF, variables assigned inside
a for-comprehension(b = a) are reported as unused.
Same snippet in 2.13.14 works fine.

Explain how the above behavior isn't what you expected.
Do not report it as unused since it clearly is used

Workaround

  List(("first", "second"))
    .map { a =>
      a match {
        case (_, _) =>
          for {
            a <- Some("a")
            b = a
          } yield b
      }
    }
@som-snytt
Copy link

Thanks for the report. This is fixed for 2.13.16 in scala/scala#10870

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants