@@ -417,18 +417,19 @@ class TastyImpl(val rootContext: Contexts.Context) extends scala.tasty.Tasty { s
417
417
case Trees .Block (stats, expr) => Some ((stats, expr))
418
418
case _ => None
419
419
}
420
- /** Normilizes non Blocks.
421
- * i) Put `while` and `doWhile` loops in thier own blocks: `{ def while$() = ...; while$() }`
420
+ /** Normalizes non Blocks.
421
+ * i) Put `while` and `doWhile` loops in their own blocks: `{ def while$() = ...; while$() }`
422
+ * ii) Put closures in their own blocks: `{ def anon$() = ...; closure(anon$, ...) }`
422
423
*/
423
424
private def normalizedLoops (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = tree match {
424
425
case block : tpd.Block if block.stats.size > 1 =>
425
426
def normalizeInnerLoops (stats : List [tpd.Tree ]): List [tpd.Tree ] = stats match {
426
- case (x : tpd.DefDef ) :: y :: xs if y.symbol.is( Flags . Label ) =>
427
+ case (x : tpd.DefDef ) :: y :: xs if needsNormalization(y ) =>
427
428
tpd.Block (x :: Nil , y) :: normalizeInnerLoops(xs)
428
429
case x :: xs => x :: normalizeInnerLoops(xs)
429
430
case Nil => Nil
430
431
}
431
- if (block.expr.symbol.is( Flags . Label )) {
432
+ if (needsNormalization( block.expr)) {
432
433
val stats1 = normalizeInnerLoops(block.stats.init)
433
434
val normalLoop = tpd.Block (block.stats.last :: Nil , block.expr)
434
435
tpd.Block (stats1, normalLoop)
@@ -438,6 +439,12 @@ class TastyImpl(val rootContext: Contexts.Context) extends scala.tasty.Tasty { s
438
439
}
439
440
case _ => tree
440
441
}
442
+
443
+ /** If it is the second statement of a loop or a closure. See: `normalizedLoops` */
444
+ private def needsNormalization (tree : tpd.Tree )(implicit ctx : Context ): Boolean = tree match {
445
+ case _ : tpd.Closure => true
446
+ case _ => tree.symbol.is(Flags .Label )
447
+ }
441
448
}
442
449
443
450
object Inlined extends InlinedExtractor {
0 commit comments