Skip to content

Commit 5613295

Browse files
committed
Typer should leave inline exception handlers inline.
1 parent 09c5ad4 commit 5613295

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
663663

664664
def typedTry(tree: untpd.Try, pt: Type)(implicit ctx: Context): Try = track("typedTry") {
665665
val expr1 = typed(tree.expr, pt)
666-
val handler1 = typed(tree.handler, defn.FunctionType(defn.ThrowableType :: Nil, pt))
666+
val handler1: Tree = tree.handler match {
667+
case h: untpd.Match if ((h.selector eq EmptyTree) // comes from parser
668+
|| (h.selector eq ExceptionHandlerSel)) => // during retyping
669+
val cases1 = typedCases(h.cases, defn.ThrowableType, pt)
670+
assignType(untpd.Match(ExceptionHandlerSel, cases1), cases1)
671+
case _ => typed(tree.handler, defn.FunctionType(defn.ThrowableType :: Nil, pt))
672+
}
667673
val finalizer1 = typed(tree.finalizer, defn.UnitType)
668674
assignType(cpy.Try(tree)(expr1, handler1, finalizer1), expr1, handler1)
669675
}

tests/pos/tryTyping.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ object tryTyping{
77
}
88

99
def foo2: Int = {
10-
val a: (Throwable => Int) = _ match {case _ => 2}
10+
val a2: (Throwable => Int) = _ match {case _ => 2}
1111
try{???; 1}
12-
catch a
12+
catch a2
13+
}
14+
15+
def foo3: Int = {
16+
val a3: (Int => Throwable => Int) = (b: Int) => _ match {case _ => b}
17+
try{???; 1}
18+
catch a3(3)
1319
}
1420
}

0 commit comments

Comments
 (0)