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

Open
oleg-py opened this Issue Feb 13, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Copy link

som-snytt commented Feb 14, 2019

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 SethTisue added this to the Backlog milestone Feb 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.