Skip to content

Instantly share code, notes, and snippets.

@ms-tg
Created August 6, 2013 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms-tg/6166436 to your computer and use it in GitHub Desktop.
Save ms-tg/6166436 to your computer and use it in GitHub Desktop.
From Ratan: desugar a for-comprehension to see why assignment won't work with Either RightProjections
////
// Output of running:
// $ scala -Xprint:parser -e "val e: Either[String, Int] = Right(1); for {i <- e.right; j = i + 1} yield j"
////
//
// Picked up _JAVA_OPTIONS: -Xss3m -XX:MaxPermSize=256M
// /tmp/scalacmd2064075741948415763.scala:1: error: value map is not a member
// of Product with Either[String,(Int, Int)] with Serializable
// val e: Either[String, Int] = Right(1); for {i <- e.right; j = i + 1} yield j
// ^
// one error found
// [[syntax trees at end of parser]]// Scala source: scalacmd2064075741948415763.scala
package <empty> {
object Main extends scala.ScalaObject {
def <init>() = {
super.<init>();
()
};
def main(argv: Array[String]): scala.Unit = {
val args = argv;
{
final class $anon extends scala.AnyRef {
def <init>() = {
super.<init>();
()
};
val e: Either[String, Int] = Right(1);
e.right.map(((i) => {
val j = i.$plus(1);
scala.Tuple2(i, j)
})).map(((x$1) => x$1: @scala.unchecked match {
case scala.Tuple2((i @ _), (j @ _)) => j
}))
};
new $anon()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment