Skip to content

Commit 4c90350

Browse files
committed
Avoid duplicated checks for blocks
1 parent 8e5b76d commit 4c90350

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,22 +361,16 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
361361
}
362362

363363
object IsBlock extends IsBlockModule {
364-
def unapply(x: Term)(implicit ctx: Context): Option[Block] = Block.normalizedLoops(x) match {
364+
def unapply(x: Term)(implicit ctx: Context): Option[Block] = normalizedLoops(x) match {
365365
case x: tpd.Block => Some(x)
366366
case _ => None
367367
}
368-
}
369368

370-
object Block extends BlockExtractor {
371-
def unapply(x: Term)(implicit ctx: Context): Option[(List[Statement], Term)] = normalizedLoops(x) match {
372-
case Trees.Block(stats, expr) => Some((stats, expr))
373-
case _ => None
374-
}
375369
/** Normalizes non Blocks.
376370
* i) Put `while` and `doWhile` loops in their own blocks: `{ def while$() = ...; while$() }`
377371
* ii) Put closures in their own blocks: `{ def anon$() = ...; closure(anon$, ...) }`
378372
*/
379-
private[Term] def normalizedLoops(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
373+
private def normalizedLoops(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
380374
case block: tpd.Block if block.stats.size > 1 =>
381375
def normalizeInnerLoops(stats: List[tpd.Tree]): List[tpd.Tree] = stats match {
382376
case (x: tpd.DefDef) :: y :: xs if needsNormalization(y) =>
@@ -402,6 +396,13 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
402396
}
403397
}
404398

399+
object Block extends BlockExtractor {
400+
def unapply(x: Term)(implicit ctx: Context): Option[(List[Statement], Term)] = x match {
401+
case IsBlock(x) => Some((x.stats, x.expr))
402+
case _ => None
403+
}
404+
}
405+
405406
object IsInlined extends IsInlinedModule {
406407
def unapply(x: Term)(implicit ctx: Context): Option[Inlined] = x match {
407408
case x: tpd.Inlined => Some(x)

0 commit comments

Comments
 (0)