Skip to content

Commit 18b3f30

Browse files
committed
Support EmptyTree as the cond of infinite while loops.
The generated type in that case is `NOTHING`, which matches the type of the `WhileDo` loop of `Nothing`.
1 parent 47eaa7f commit 18b3f30

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,15 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
605605
def genWhileDo(tree: WhileDo): BType = tree match{
606606
case WhileDo(cond, body) =>
607607

608-
val isInfinite = cond match {
609-
case Literal(value) if value.tag == BooleanTag => value.booleanValue
610-
case _ => false
611-
}
608+
val isInfinite = cond == EmptyTree
612609

613610
val loop = new asm.Label
614611
markProgramPoint(loop)
615612

616613
if (isInfinite) {
617614
genLoad(body, UNIT)
618615
bc goTo loop
616+
RT_NOTHING
619617
} else {
620618
val hasBody = cond match {
621619
case Literal(value) if value.tag == UnitTag => false
@@ -636,9 +634,9 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
636634
genCond(cond, loop, failure, targetIfNoJump = failure)
637635
markProgramPoint(failure)
638636
}
639-
}
640637

641-
UNIT
638+
UNIT
639+
}
642640
}
643641

644642
def genTypeApply(t: TypeApply): BType = t match {

0 commit comments

Comments
 (0)