Skip to content

Commit 2808cbe

Browse files
committed
Pass by name should not introduce boxing
1 parent 2d72287 commit 2808cbe

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ class Compiler {
6969
new ExplicitSelf, // Make references to non-trivial self types explicit as casts
7070
new ShortcutImplicits, // Allow implicit functions without creating closures
7171
new CrossCastAnd, // Normalize selections involving intersection types.
72-
new Splitter, // Expand selections involving union types into conditionals
73-
new SpecializeFunctions), // Specialized Function1 by replacing super with specialized super
72+
new Splitter), // Expand selections involving union types into conditionals
7473
List(new PhantomArgLift, // Extracts the evaluation of phantom arguments placing them before the call.
7574
new VCInlineMethods, // Inlines calls to value class methods
7675
new SeqLiterals, // Express vararg arguments as arrays
7776
new InterceptedMethods, // Special handling of `==`, `|=`, `getClass` methods
7877
new Getters, // Replace non-private vals and vars with getter defs (fields are added later)
79-
new ElimByName, // Expand by-name parameter references
78+
new ElimByName), // Expand by-name parameter references
79+
List(new SpecializeFunctions, // Specialized Function{0,1,2} by replacing super with specialized super
8080
new ElimOuterSelect, // Expand outer selections
8181
new AugmentScala2Traits, // Expand traits defined in Scala 2.x to simulate old-style rewritings
8282
new ResolveSuper, // Implement super accessors and add forwarders to trait methods

compiler/test/dotty/tools/dotc/transform/SpecializeFunctionsTests.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,16 @@ class SpecializeFunctionsTests extends DottyBytecodeTest {
214214
assertBoxing("<init>", findClass("Test$", dir).methods)
215215
}
216216
}
217+
218+
@Test def passByNameNoBoxing = {
219+
implicit val source: String =
220+
"""|object Test {
221+
| def fn(x: => Int): Int = x
222+
| fn(2)
223+
|}""".stripMargin
224+
225+
checkBCode(source) { dir =>
226+
assertNoBoxing("fn", findClass("Test$", dir).methods)
227+
}
228+
}
217229
}

0 commit comments

Comments
 (0)