Skip to content

Commit

Permalink
Merge pull request #13944 from KacperFKorban/fix-i13941
Browse files Browse the repository at this point in the history
Don't lift try-catch statements that are already in local functions
  • Loading branch information
odersky committed Jan 23, 2022
2 parents 7ce60e1 + abd4998 commit a018159
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/LiftTry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class LiftTry extends MiniPhase with IdentityDenotTransformer { thisPhase =>
override def prepareForApply(tree: Apply)(using Context): Context =
liftingCtx(true)

override def prepareForDefDef(tree: DefDef)(using Context): Context =
liftingCtx(false)

override def prepareForValDef(tree: ValDef)(using Context): Context =
if !tree.symbol.exists
|| tree.symbol.isSelfSym
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i13941.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import scala.annotation.tailrec

object A {
def b = Option("a").map { x =>
@tailrec
def loop(): Int = {
try
2
catch
case _: Throwable =>
loop()
}
x
}
}

0 comments on commit a018159

Please sign in to comment.