@@ -417,18 +417,19 @@ class TastyImpl(val rootContext: Contexts.Context) extends scala.tasty.Tasty { s
417417 case Trees .Block (stats, expr) => Some ((stats, expr))
418418 case _ => None
419419 }
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$, ...) }`
422423 */
423424 private def normalizedLoops (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = tree match {
424425 case block : tpd.Block if block.stats.size > 1 =>
425426 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 ) =>
427428 tpd.Block (x :: Nil , y) :: normalizeInnerLoops(xs)
428429 case x :: xs => x :: normalizeInnerLoops(xs)
429430 case Nil => Nil
430431 }
431- if (block.expr.symbol.is( Flags . Label )) {
432+ if (needsNormalization( block.expr)) {
432433 val stats1 = normalizeInnerLoops(block.stats.init)
433434 val normalLoop = tpd.Block (block.stats.last :: Nil , block.expr)
434435 tpd.Block (stats1, normalLoop)
@@ -438,6 +439,12 @@ class TastyImpl(val rootContext: Contexts.Context) extends scala.tasty.Tasty { s
438439 }
439440 case _ => tree
440441 }
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+ }
441448 }
442449
443450 object Inlined extends InlinedExtractor {
0 commit comments