Closed scabug closed 7 years ago
Imported From: https://issues.scala-lang.org/browse/SI-9158?orig=1 Reporter: Andrey Kuznetsov (prettynatty) Affected Versions: 2.11.5 See #7712
@retronym said: We removed this option from -Xlint in #7712 because, as you have found, it is somewhat incomplete.
@som-snytt said: One way to look at it is that the warning is there to keep you from doing something unintentional.
The warning is not spurious, in that the for comprehension desugars into an extra packaging step; it's the for comprehension equivalent of autoboxing.
See the part where he goes, "Wait, really?" The locals in the yield block are unused.
Intended:
for {
tup <- optTup
} yield {
val (num1, num2) = tup
(num1 + num2)
}
Andrey Kuznetsov (prettynatty) said (edited on Feb 18, 2015 9:55:45 PM UTC): But what if I want to write the something like this? Such code throws warning too.
for {
tup1 <- optTup
(num1, num2) = tup1
tup2 <- fn(num2, num1)
} yield {
tup2 // or anything else
}
Is it really unintended?
@som-snytt said: Here is another example that could benefit from more efficient handling of intermediate results.
Because the unused extraction result i
is not bundled in the tupling step, the extractor is invoked three times.
scala> for (s <- List("ab","abc") ; X(i) = s if i > 2) yield i // show
[snip]
val res0 = List("ab", "abc").map(((s) => {
<synthetic> <artifact> private[this] val x$2 = s: @scala.unchecked match {
case (x$1 @ X((i @ _))) => scala.Tuple2(x$1, i)
};
val x$1 = x$2._1;
val i = x$2._2;
scala.Tuple2(s, x$1)
})).withFilter(((x$3) => x$3: @scala.unchecked match {
case scala.Tuple2((s @ _), X((i @ _))) => i > 2
})).map(((x$4) => x$4: @scala.unchecked match {
case scala.Tuple2((s @ _), X((i @ _))) => i
}))
}
}
}
@som-snytt said:
The PR tags the binds as if they were (i @ *, j @ *) = t
which is the way to disable the warning in source.