Skip to content
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

-Ywarn-unused:patvars false positive in for-comprehension #11400

Closed
oleg-py opened this issue Feb 13, 2019 · 2 comments
Closed

-Ywarn-unused:patvars false positive in for-comprehension #11400

oleg-py opened this issue Feb 13, 2019 · 2 comments

Comments

@oleg-py
Copy link

oleg-py commented Feb 13, 2019

Tested on Scala 2.12.8 and 2.13.0-M5.

Compiling this object with -Ywarn-unused:patvars

object Warnings {
  case class Foo(bar: Int, buzz: String)

  def test = for {
    foo @ Foo(bar, buzz) <- List(Foo(1, "x"))
    x = s"$bar $buzz $foo"
  } yield x
  
  def main(args: Array[String]) = println(test)
}

results in a warning:

pattern var foo in value $anonfun is never used; `foo@_' suppresses this warning

This is probably caused by desugaring of the above for-comprehension, being roughly:

List(Foo(1, "x")).map({
  case (foo @ Foo((bar @ _), (buzz @ _))) =>
    val x = StringContext("", " ", " ", "").s(bar, buzz, foo);
    (foo, x)
}).map({
  case ((foo @ Foo((bar @ _), (buzz @ _))), (x @ _)) => x
}));

Note that exact same pattern used in first map is carried over to the second map, even though now its variables aren't used.

@som-snytt
Copy link

This duplicates #10287 where, as you note, the desugaring makes it too much of a bother. Leaving open to track use cases (test cases).

@SethTisue
Copy link
Member

consolidating at #10287

@SethTisue SethTisue removed this from the Backlog milestone May 29, 2020
@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2023
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