Skip to content

Commit be03a4d

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 cadf301 commit be03a4d

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
@@ -300,8 +300,11 @@ trait TypeAssigner {
300300
tree.withType(defn.NothingType)
301301

302302
def assignType(tree: untpd.Try, expr: Tree, handler: Tree)(implicit ctx: Context) = {
303-
val handlerTypeArgs = handler.tpe.baseArgTypesHi(defn.FunctionClass(1))
304-
tree.withType(if (handlerTypeArgs.nonEmpty) expr.tpe | handlerTypeArgs(1) else expr.tpe)
303+
if(handler.isEmpty) tree.withType(expr.tpe)
304+
else if(handler.tpe.derivesFrom(defn.FunctionClass(1))) {
305+
val handlerTypeArgs = handler.tpe.baseArgTypesHi(defn.FunctionClass(1))
306+
tree.withType(if (handlerTypeArgs.nonEmpty) expr.tpe | handlerTypeArgs(1) else expr.tpe /*| Object, as function returns boxed value ??? */)
307+
} else tree.withType(expr.tpe | handler.tpe)
305308
}
306309

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

0 commit comments

Comments
 (0)