Skip to content

Commit 8ae3820

Browse files
committed
Remove Block normalization from BlockTypeTest
1 parent 5b5bd67 commit 8ae3820

File tree

1 file changed

+3
-34
lines changed

1 file changed

+3
-34
lines changed

compiler/src/scala/quoted/internal/impl/QuoteContextImpl.scala

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -679,40 +679,9 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl
679679
type Block = tpd.Block
680680

681681
val BlockTypeTest: TypeTest[Tree, Block] = new {
682-
def unapply(x: Tree): Option[Block & x.type] =
683-
normalizedLoops(x) match
684-
case y: tpd.Block => Some(y.asInstanceOf[Block & x.type]) // FIXME return x
685-
case _ => None
686-
687-
/** Normalizes non Blocks.
688-
* i) Put `while` loops in their own blocks: `{ def while$() = ...; while$() }`
689-
* ii) Put closures in their own blocks: `{ def anon$() = ...; closure(anon$, ...) }`
690-
*/
691-
private def normalizedLoops(tree: tpd.Tree): tpd.Tree = tree match {
692-
case block: tpd.Block if block.stats.size > 1 =>
693-
def normalizeInnerLoops(stats: List[tpd.Tree]): List[tpd.Tree] = stats match {
694-
case (x: tpd.DefDef) :: y :: xs if needsNormalization(y) =>
695-
tpd.Block(x :: Nil, y) :: normalizeInnerLoops(xs)
696-
case x :: xs => x :: normalizeInnerLoops(xs)
697-
case Nil => Nil
698-
}
699-
if (needsNormalization(block.expr)) {
700-
val stats1 = normalizeInnerLoops(block.stats.init)
701-
val normalLoop = tpd.Block(block.stats.last :: Nil, block.expr)
702-
tpd.Block(stats1, normalLoop)
703-
}
704-
else {
705-
val stats1 = normalizeInnerLoops(block.stats)
706-
tpd.cpy.Block(block)(stats1, block.expr)
707-
}
708-
case _ => tree
709-
}
710-
711-
/** If it is the second statement of a closure. See: `normalizedLoops` */
712-
private def needsNormalization(tree: tpd.Tree): Boolean = tree match {
713-
case _: tpd.Closure => true
714-
case _ => false
715-
}
682+
def unapply(x: Tree): Option[Block & x.type] = x match
683+
case x: (tpd.Block & x.type) => Some(x)
684+
case _ => None
716685
}
717686

718687
object Block extends BlockModule:

0 commit comments

Comments
 (0)