@@ -21,6 +21,7 @@ import Flags._
21
21
import Decorators ._
22
22
import ErrorReporting ._
23
23
import EtaExpansion .etaExpand
24
+ import dotty .tools .dotc .transform .Erasure .Boxing
24
25
import util .Positions ._
25
26
import util .common ._
26
27
import util .SourcePosition
@@ -344,6 +345,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
344
345
assignType(cpy.Typed (tree)(expr1, tpt1), tpt1)
345
346
}
346
347
tree.expr match {
348
+ case ExceptionHandlerSel if (tree.tpt.tpe == defn.ThrowableType ) =>
349
+ tree withType defn.ThrowableType
347
350
case id : untpd.Ident if (ctx.mode is Mode .Pattern ) && isVarPattern(id) =>
348
351
if (id.name == nme.WILDCARD ) regularTyped(isWildcard = true )
349
352
else {
@@ -676,8 +679,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
676
679
case h : untpd.Match if ((h.selector eq EmptyTree ) // comes from parser
677
680
|| (h.selector eq ExceptionHandlerSel )) => // during retyping
678
681
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)
680
687
case _ => typed(tree.handler, defn.FunctionType (defn.ThrowableType :: Nil , pt))
688
+
681
689
}
682
690
val finalizer1 = typed(tree.finalizer, defn.UnitType )
683
691
assignType(cpy.Try (tree)(expr1, handler1, finalizer1), expr1, handler1)
0 commit comments