Skip to content

Commit c437512

Browse files
committed
Avoid erasing side effects of argumet of Unit.{box|unbox}
1 parent 212b630 commit c437512

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,8 @@ object Erasure {
477477
*/
478478
override def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
479479
val Apply(fun, args) = tree
480-
if (fun.symbol == defn.cbnArg)
480+
if (fun.symbol == defn.cbnArg || (tree.symbol.name == nme.box || tree.symbol.name == nme.unbox) && tree.symbol.owner.asClass.companionClass == defn.UnitClass)
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)
483482
else typedExpr(fun, FunProto(args, pt, this)) match {
484483
case fun1: Apply => // arguments passed in prototype were already passed
485484
fun1

tests/run/i3518.check

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

tests/run/i3518.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ object Test {
44
Unit.unbox(Unit.box(()))
55
println(Unit.box(()))
66
println(Unit.unbox(Unit.box(())))
7+
println(Unit.box({
8+
println("A")
9+
()
10+
}))
711
}
812
}

0 commit comments

Comments
 (0)