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

No warning for unused patvars in for comprehension assignment #13070

Open
som-snytt opened this issue Dec 19, 2024 · 0 comments
Open

No warning for unused patvars in for comprehension assignment #13070

som-snytt opened this issue Dec 19, 2024 · 0 comments

Comments

@som-snytt
Copy link

Questions are not bug reports

I had a question...

Reproduction steps

Scala version: 2.13.16

class C {
  def g = {
    val t = Option((27, 42))
    for {
      ns <- t
      (i, j) = ns
    } yield 42
  }
}

Problem

Does not warn unused i, j under -Wunused.

It correctly does not warn for the unused "intermediates" during the tupling map, but should warn because they are not used after that.

The existing test only verifies that it does not yield a false positive under -Wunused:-patvars (turned off).

package <empty> {
  class C extends scala.AnyRef {
    def <init>(): C = {
      C.super.<init>();
      ()
    };
    def g: Option[Int] = {
      val t: Option[(Int, Int)] = scala.Option.apply[(Int, Int)](scala.Tuple2.apply[Int, Int](17, 42));
      t.map[((Int, Int), (Int, Int))](((ns: (Int, Int)) => {
  <synthetic> <artifact> private[this] val x$2: ((Int, Int), Int, Int) = (ns: (Int, Int) @unchecked) match {
    case (x$1 @ (_1: Int, _2: Int): (Int, Int)((i @ _), (j @ _))) => scala.Tuple3.apply[(Int, Int), Int, Int](x$1, i, j)
  };
  val x$1: (Int, Int) = x$2._1;
  val i: Int = x$2._2;
  val j: Int = x$2._3;
  scala.Tuple2.apply[(Int, Int), (Int, Int)](ns, x$1)
})).map[Int](((x$3: ((Int, Int), (Int, Int))) => (x$3: ((Int, Int), (Int, Int)) @unchecked) match {
        case (_1: (Int, Int), _2: (Int, Int)): ((Int, Int), (Int, Int))((ns @ _), (_1: Int, _2: Int): (Int, Int)((i @ _), (j @ _))) => 42
      }))
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant