Skip to content

Fix #3518: Do not generate calls to BoxesRunTime for Unit box/unbox #3522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
s eq defn.newArrayMethod
}

def isBox(sym: Symbol): Boolean = Erasure.Boxing.isBox(sym)
def isUnbox(sym: Symbol): Boolean = Erasure.Boxing.isUnbox(sym)
def isBox(sym: Symbol): Boolean =
Erasure.Boxing.isBox(sym) && sym.denot.owner != defn.UnitModuleClass
def isUnbox(sym: Symbol): Boolean =
Erasure.Boxing.isUnbox(sym) && sym.denot.owner != defn.UnitModuleClass

val primitives: Primitives = new Primitives {
val primitives = new DottyPrimitives(ctx)
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ class Definitions {

lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", BoxedUnitType, java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
def UnitClass(implicit ctx: Context) = UnitType.symbol.asClass
def UnitModuleClass(implicit ctx: Context) = UnitType.symbol.asClass.linkedClass
lazy val BooleanType = valueTypeRef("scala.Boolean", BoxedBooleanType, java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
def BooleanClass(implicit ctx: Context) = BooleanType.symbol.asClass
lazy val Boolean_notR = BooleanClass.requiredMethodRef(nme.UNARY_!)
Expand Down
4 changes: 4 additions & 0 deletions tests/run/i3518.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
()
()
A
()
12 changes: 12 additions & 0 deletions tests/run/i3518.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
object Test {
def main(args: Array[String]): Unit = {
Unit.box(())
Unit.unbox(Unit.box(()))
println(Unit.box(()))
println(Unit.unbox(Unit.box(())))
println(Unit.box({
println("A")
()
}))
}
}