Skip to content

Commit 7c49506

Browse files
committed
Enhance forallResults to handle Try
1 parent d884df3 commit 7c49506

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,8 +1557,6 @@ object desugar {
15571557

15581558
val ids = for ((named, tpt) <- vars) yield Ident(named.name)
15591559

1560-
// println(s"fullTupleOptimizable = $fullTupleOptimizable, partialTupleOptimizable = $partialTupleOptimizable, ids = $ids")
1561-
15621560
val matchExpr =
15631561
if fullTupleOptimizable then rhs
15641562
else

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,16 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
350350
}
351351

352352
/** Checks whether predicate `p` is true for all result parts of this expression,
353-
* where we zoom into Ifs, Matches, and Blocks.
353+
* where we zoom into Ifs, Matches, Tries, and Blocks.
354354
*/
355-
def forallResults(tree: Tree, p: Tree => Boolean): Boolean = tree match {
355+
def forallResults(tree: Tree, p: Tree => Boolean): Boolean = tree match
356356
case If(_, thenp, elsep) => forallResults(thenp, p) && forallResults(elsep, p)
357-
case Match(_, cases) => cases forall (c => forallResults(c.body, p))
357+
case Match(_, cases) => cases.forall(c => forallResults(c.body, p))
358+
case Try(_, cases, finalizer) =>
359+
cases.forall(c => forallResults(c.body, p))
360+
&& (finalizer.isEmpty || forallResults(finalizer, p))
358361
case Block(_, expr) => forallResults(expr, p)
359362
case _ => p(tree)
360-
}
361363

362364
/** The tree stripped of the possibly nested applications (term and type).
363365
* The original tree if it's not an application.

0 commit comments

Comments
 (0)