Skip to content

Commit 212b630

Browse files
committed
Fix #3518: Erase explicit Unit.box and Unit.unbox in erasure
1 parent c48f7b0 commit 212b630

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ object Erasure {
479479
val Apply(fun, args) = tree
480480
if (fun.symbol == defn.cbnArg)
481481
typedUnadapted(args.head, pt)
482+
else if ((tree.symbol.name == nme.box || tree.symbol.name == nme.unbox) && tree.symbol.owner.asClass.companionClass == defn.UnitClass) ref(defn.BoxedUnit_UNIT)
482483
else typedExpr(fun, FunProto(args, pt, this)) match {
483484
case fun1: Apply => // arguments passed in prototype were already passed
484485
fun1

tests/run/i3518.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
()
2+
()

tests/run/i3518.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
Unit.box(())
4+
Unit.unbox(Unit.box(()))
5+
println(Unit.box(()))
6+
println(Unit.unbox(Unit.box(())))
7+
}
8+
}

0 commit comments

Comments
 (0)