Skip to content

Commit 4987093

Browse files
committed
Fixing new LabelDefs with -optimise
1 parent a124d9e commit 4987093

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/DropNoEffects.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package dotty.tools.dotc
22
package transform.localopt
33

4-
import core.TypeErasure
54
import core.Contexts.Context
65
import core.Symbols._
76
import core.Types._
87
import core.Flags._
8+
import core.StdNames._
99
import ast.Trees._
1010
import Simplify._
1111

@@ -36,7 +36,7 @@ class DropNoEffects(val simplifyPhase: Simplify) extends Optimisation {
3636
case t => t :: Nil
3737
}
3838
val (newStats2, newExpr) = a.expr match {
39-
case Block(stats2, expr) => (newStats1 ++ stats2, expr)
39+
case Block(stats2, expr) if !isWhileLabel(expr.symbol) => (newStats1 ++ stats2, expr)
4040
case _ => (newStats1, a.expr)
4141
}
4242

@@ -201,4 +201,7 @@ class DropNoEffects(val simplifyPhase: Simplify) extends Optimisation {
201201
case _ =>
202202
false
203203
}
204+
205+
private def isWhileLabel(sym: Symbol)(implicit ctx: Context): Boolean =
206+
sym.is(Label) && (sym.name == nme.WHILE_PREFIX || sym.name == nme.DO_WHILE_PREFIX)
204207
}

tests/pos/nested-do-while.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
def foo(): Unit = {
3+
val elems: Iterator[Int] = ???
4+
do {
5+
elems.next()
6+
do elems.next() while (elems.hasNext)
7+
} while (elems.hasNext)
8+
}
9+
}

tests/pos/nested-while.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
def foo(): Unit = {
3+
val elems: Iterator[Int] = ???
4+
while (elems.hasNext) {
5+
elems.next()
6+
while (elems.hasNext) elems.next()
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)