Skip to content

Commit 37c2dcc

Browse files
committed
Do not box Unit inside try, match and if branches.
1 parent 19215a8 commit 37c2dcc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,13 @@ object Erasure extends TypeTestsCasts{
403403
override def typedTry(tree: untpd.Try, pt: Type)(implicit ctx: Context) =
404404
super.typedTry(tree, adaptProto(tree, pt))
405405

406-
private def adaptProto(tree: untpd.Tree, pt: Type)(implicit ctx: Context) =
407-
if (pt.isValueType) pt else erasure(tree.typeOpt)
406+
private def adaptProto(tree: untpd.Tree, pt: Type)(implicit ctx: Context) = {
407+
if (pt.isValueType) pt else {
408+
if(tree.typeOpt.derivesFrom(ctx.definitions.UnitClass))
409+
tree.typeOpt
410+
else erasure(tree.typeOpt)
411+
}
412+
}
408413

409414
override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context): ValDef =
410415
super.typedValDef(untpd.cpy.ValDef(vdef)(

0 commit comments

Comments
 (0)