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
For comprehension returning unexpected type with unused midstream assignment #7515
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7515?orig=1 |
@retronym said: scala> for ((k, v) <- Map("a" -> "b"); (a, b) = (k.length, v.length)) yield v -> k
res1: scala.collection.immutable.Map[String,String] = Map(b -> a) |
not fixed in Scala 3: scala/scala3#16812 |
When you consider that intermediate variables in for-comprehensions desugar to import scala.reflect.runtime.universe._
println(reify(for ((k, v) <- Map("a" -> "b"); a = k.length; b = v.length) yield v -> k)) Expr[scala.collection.immutable.Iterable[(String, String)]](Predef.Map.apply(Predef.ArrowAssoc("a").$minus$greater("b")).withFilter(((check$ifrefutable$1) => check$ifrefutable$1: @unchecked match {
case Tuple2((k @ _), (v @ _)) => true
case _ => false
})).map(((x$2) => x$2: @unchecked match {
case (x$1 @ Tuple2((k @ _), (v @ _))) => {
val a = k.length();
val b = v.length();
Tuple3.apply(x$1, a, b)
}
})).map(((x$3) => x$3: @unchecked match {
case Tuple3(Tuple2((k @ _), (v @ _)), (a @ _), (b @ _)) => Predef.ArrowAssoc(v).$minus$greater(k)
}))) Of course the intermediate |
But:
See scala-internals thread:
https://groups.google.com/forum/#!topic/scala-internals/Cmh0Co9xcMs
The text was updated successfully, but these errors were encountered: