Skip to content

Commit 52c445f

Browse files
committed
Create def with closure extractor in TreeInfo
1 parent 0bc7827 commit 52c445f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,18 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
534534
}
535535
}
536536

537+
/** An extractor for closures with their def contained in a block. */
538+
object closureWithDef {
539+
def unapply(tree: Tree): Option[(DefDef, Closure)] = tree match {
540+
case Block((meth @ DefDef(nme.ANON_FUN, _, _, _, _)) :: Nil, closure: Closure) =>
541+
Some(meth, closure)
542+
case _ => None
543+
}
544+
}
545+
537546
/** If tree is a closure, its body, otherwise tree itself */
538547
def closureBody(tree: Tree)(implicit ctx: Context): Tree = tree match {
539-
case Block((meth @ DefDef(nme.ANON_FUN, _, _, _, _)) :: Nil, Closure(_, _, _)) => meth.rhs
548+
case closureWithDef(meth, _) => meth.rhs
540549
case _ => tree
541550
}
542551

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ object PickledQuotes {
126126
val x1 = SyntheticValDef(NameKinds.UniqueName.fresh("x".toTermName), x)
127127
def x1Ref() = ref(x1.symbol)
128128
def rec(f: Tree): Tree = f match {
129-
case Block((ddef: DefDef) :: Nil, _: Closure) =>
129+
case closureWithDef(ddef, _) =>
130130
new TreeMap() {
131131
private val paramSym = ddef.vparamss.head.head.symbol
132132
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {

0 commit comments

Comments
 (0)