scala> def test(a: Option[Int], b: Int) = (a, b) match { case (Some(x), y) => x + y; case (None, y) => y }
[[syntax trees at end of patmat]] // <console>
def test(a: Option[Int], b: Int): Int = {
case <synthetic> val x1: (Option[Int], Int) = scala.Tuple2.apply[Option[Int], Int](a, b);
case8() {
if (x1.ne(null)) {
<synthetic> val p2: Option[Int] = x1._1;
val y: Int = x1._2;
if (p2.isInstanceOf[Some[Int]]) {
<synthetic> val x3: Some[Int] = (p2.asInstanceOf[Some[Int]]: Some[Int]);
{
val x: Int = x3.value;
matchEnd7(x.+(y))
}
}
else
case9()
}
else
case9()
};
case9() {
if (x1.ne(null)) {
<synthetic> val p4: Option[Int] = x1._1;
val y: Int = x1._2;
if (scala.None.==(p4))
matchEnd7(y)
else
case10()
}
else
case10()
};
case10() {
matchEnd7(throw new MatchError(x1))
};
matchEnd7(x: Int) {
x
}
}
note that the tuple (local 4) is only used at instruction 60, to produce a MatchError which can only be hit when a is null. we should float the tuple construction into the failure case.
note that the tuple (local 4) is only used at instruction 60, to produce a
MatchError
which can only be hit whena
isnull
. we should float the tuple construction into the failure case.toth @fommil for pointing this out (a year ago)