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

Closed
som-snytt opened this issue Dec 19, 2024 · 1 comment · Fixed by scala/scala#10980
Closed

No warning for unused patvars in for comprehension assignment #13070

som-snytt opened this issue Dec 19, 2024 · 1 comment · Fixed by scala/scala#10980
Milestone

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
      }))
    }
  }
}
@som-snytt
Copy link
Author

Verified it works under the port to dotty in scala/scala3#20894

-- [E198] Unused Symbol Warning: t13070.scala:7:7 ------------------------------
7 |      (i, j) = ns
  |       ^
  |       unused pattern variable
-- [E198] Unused Symbol Warning: t13070.scala:7:10 -----------------------------
7 |      (i, j) = ns
  |          ^
  |          unused pattern variable
2 warnings found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant