This is not a bug in the backend, but in the parser IMO, because it doesn't add an empty block in one of the two cases. Here is a slightly modified example:
object foo {
def f():Unit = {
1.match {
case 2 => val _ = 1;
case 3 => val _ = 2;
case 4 => val _ = 2;
}
}
}
and here is how it looks after parsing:
[[Trees after phase parse]]
// Scala source: bug_159.scala
object foo extends scala.Object() {
def f(): Unit = 1.match({
case 2 => {
val _ = 1
}
case 3 => {
val _ = 2
}
case 4 => {
val _ = 2;
{
}
}
})
};
As you can see, only the last case is correct, because the implicit empty block representing "unit" has indeed been added. This implicit unit is, however, missing in the two other cases. If you feed this code again in the compiler, it complains.
For now, a work-around is to explicitely put "unit" values in the code, like that:
object foo {
def f():Unit = {
1.match {
case 2 => val _ = 1; ()
case 3 => val _ = 2; ()
case 4 => val _ = 2; ()
}
}
}
|