Skip to content

Commit 40a25fd

Browse files
committed
Fix #3518: Do not generate calls to BoxesRunTime for Unit box/unbox
1 parent c48f7b0 commit 40a25fd

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
169169
s eq defn.newArrayMethod
170170
}
171171

172-
def isBox(sym: Symbol): Boolean = Erasure.Boxing.isBox(sym)
173-
def isUnbox(sym: Symbol): Boolean = Erasure.Boxing.isUnbox(sym)
172+
def isBox(sym: Symbol): Boolean = Erasure.Boxing.isBox(sym) && !isInUnit(sym)
173+
def isUnbox(sym: Symbol): Boolean = Erasure.Boxing.isUnbox(sym) && !isInUnit(sym)
174+
175+
private def isInUnit(sym: Symbol) = sym.denot.owner.denot.linkedClass == defn.UnitClass
174176

175177
val primitives: Primitives = new Primitives {
176178
val primitives = new DottyPrimitives(ctx)

tests/run/i3518.check

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

tests/run/i3518.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
println(Unit.box({
8+
println("A")
9+
()
10+
}))
11+
}
12+
}

0 commit comments

Comments
 (0)