Skip to content

Commit cadf301

Browse files
committed
Make typing of Try nodes idempotent
1 parent ee3ac06 commit cadf301

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/dotty/tools/dotc/transform/TailRec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
237237
case Block(List((d: DefDef)), cl@Closure(Nil, _, EmptyTree)) =>
238238
val newDef = cpy.DefDef(d)(rhs = transform(d.rhs))
239239
Block(List(newDef), cl)
240-
case Match(ExceptionHandlerSel, _) =>
240+
case Match(Typed(ExceptionHandlerSel, _), _) =>
241241
transform(t)
242242
case _: Ident|_: Apply| _: TypeApply => t // handler is an external function
243243
case _ => assert(false, s"failed to deconstruct try handler ${t.show}"); ???

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Flags._
2121
import Decorators._
2222
import ErrorReporting._
2323
import EtaExpansion.etaExpand
24+
import dotty.tools.dotc.transform.Erasure.Boxing
2425
import util.Positions._
2526
import util.common._
2627
import util.SourcePosition
@@ -344,6 +345,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
344345
assignType(cpy.Typed(tree)(expr1, tpt1), tpt1)
345346
}
346347
tree.expr match {
348+
case ExceptionHandlerSel if (tree.tpt.tpe == defn.ThrowableType) =>
349+
tree withType defn.ThrowableType
347350
case id: untpd.Ident if (ctx.mode is Mode.Pattern) && isVarPattern(id) =>
348351
if (id.name == nme.WILDCARD) regularTyped(isWildcard = true)
349352
else {
@@ -676,8 +679,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
676679
case h: untpd.Match if ((h.selector eq EmptyTree) // comes from parser
677680
|| (h.selector eq ExceptionHandlerSel)) => // during retyping
678681
val cases1 = typedCases(h.cases, defn.ThrowableType, pt)
679-
assignType(untpd.Match(ExceptionHandlerSel, cases1), cases1)
682+
assignType(untpd.Match(Typed(ExceptionHandlerSel, TypeTree(defn.ThrowableType)), cases1), cases1)
683+
case Typed(handler, tpe) if ctx.phaseId > ctx.patmatPhase.id => // we are retyping an expanded pattern
684+
typed(tree.handler, pt)
685+
case Apply(bx, List(Typed(handler, tpe))) if ctx.erasedTypes && Boxing.isBox(bx.symbol) =>
686+
typed(tree.handler, pt)
680687
case _ => typed(tree.handler, defn.FunctionType(defn.ThrowableType :: Nil, pt))
688+
681689
}
682690
val finalizer1 = typed(tree.finalizer, defn.UnitType)
683691
assignType(cpy.Try(tree)(expr1, handler1, finalizer1), expr1, handler1)

0 commit comments

Comments
 (0)