aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala8
-rw-r--r--tests/pos/tryTyping.scala10
2 files changed, 15 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 42b973eed..e7b6f45d4 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -663,7 +663,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def typedTry(tree: untpd.Try, pt: Type)(implicit ctx: Context): Try = track("typedTry") {
val expr1 = typed(tree.expr, pt)
- val handler1 = typed(tree.handler, defn.FunctionType(defn.ThrowableType :: Nil, pt))
+ val handler1: Tree = tree.handler match {
+ case h: untpd.Match if ((h.selector eq EmptyTree) // comes from parser
+ || (h.selector eq ExceptionHandlerSel)) => // during retyping
+ val cases1 = typedCases(h.cases, defn.ThrowableType, pt)
+ assignType(untpd.Match(ExceptionHandlerSel, cases1), cases1)
+ case _ => typed(tree.handler, defn.FunctionType(defn.ThrowableType :: Nil, pt))
+ }
val finalizer1 = typed(tree.finalizer, defn.UnitType)
assignType(cpy.Try(tree)(expr1, handler1, finalizer1), expr1, handler1)
}
diff --git a/tests/pos/tryTyping.scala b/tests/pos/tryTyping.scala
index 35180bee9..a2aeb17c8 100644
--- a/tests/pos/tryTyping.scala
+++ b/tests/pos/tryTyping.scala
@@ -7,8 +7,14 @@ object tryTyping{
}
def foo2: Int = {
- val a: (Throwable => Int) = _ match {case _ => 2}
+ val a2: (Throwable => Int) = _ match {case _ => 2}
try{???; 1}
- catch a
+ catch a2
+ }
+
+ def foo3: Int = {
+ val a3: (Int => Throwable => Int) = (b: Int) => _ match {case _ => b}
+ try{???; 1}
+ catch a3(3)
}
} \ No newline at end of file