aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/TreeInfo.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/ast/TreeInfo.scala')
-rw-r--r--src/dotty/tools/dotc/ast/TreeInfo.scala10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/ast/TreeInfo.scala b/src/dotty/tools/dotc/ast/TreeInfo.scala
index 29ff492d4..e1715ae26 100644
--- a/src/dotty/tools/dotc/ast/TreeInfo.scala
+++ b/src/dotty/tools/dotc/ast/TreeInfo.scala
@@ -260,6 +260,16 @@ trait TreeInfo[T >: Untyped] { self: Trees.Instance[T] =>
case Bind(_, y) => unbind(y)
case y => y
}
+
+ /** Checks whether predicate `p` is true for all result parts of this epression,
+ * where we zoom into Ifs, Matches, and Blocks.
+ */
+ def forallResults(tree: Tree, p: Tree => Boolean): Boolean = tree match {
+ case If(_, thenp, elsep) => forallResults(thenp, p) && forallResults(elsep, p)
+ case Match(_, cases) => cases forall (c => forallResults(c.body, p))
+ case Block(_, expr) => forallResults(expr, p)
+ case _ => p(tree)
+ }
}
trait TypedTreeInfo extends TreeInfo[Type] {self: Trees.Instance[Type] =>