Skip to content

Commit 6dcd16a

Browse files
committed
Rewrite assignType for Try
After erasure was always wrong(didn't include the type of handler). Now it's able to use both Closures and desugared Math nodes.
1 parent d923d70 commit 6dcd16a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,11 @@ trait TypeAssigner {
314314
tree.withType(defn.NothingType)
315315

316316
def assignType(tree: untpd.Try, expr: Tree, handler: Tree)(implicit ctx: Context) = {
317-
val handlerTypeArgs = handler.tpe.baseArgTypesHi(defn.FunctionClass(1))
318-
tree.withType(if (handlerTypeArgs.nonEmpty) expr.tpe | handlerTypeArgs(1) else expr.tpe)
317+
if(handler.isEmpty) tree.withType(expr.tpe)
318+
else if(handler.tpe.derivesFrom(defn.FunctionClass(1))) {
319+
val handlerTypeArgs = handler.tpe.baseArgTypesHi(defn.FunctionClass(1))
320+
tree.withType(if (handlerTypeArgs.nonEmpty) expr.tpe | handlerTypeArgs(1) else expr.tpe /*| Object, as function returns boxed value ??? */)
321+
} else tree.withType(expr.tpe | handler.tpe)
319322
}
320323

321324
def assignType(tree: untpd.Throw)(implicit ctx: Context) =

0 commit comments

Comments
 (0)