@@ -12,6 +12,21 @@ class SpecializeFunction1Tests extends DottyBytecodeTest {
12
12
import dotty .tools .backend .jvm .ASMConverters ._
13
13
import dotty .tools .backend .jvm .AsmNode ._
14
14
15
+ protected def checkForBoxing (ins : List [Instruction ], source : String ): Unit = ins.foreach {
16
+ case Invoke (op, owner, name, desc, itf) =>
17
+ def error =
18
+ s """ |----------------------------------
19
+ | ${ins.mkString(" \n " )}
20
+ |----------------------------------
21
+ |From code:
22
+ | $source
23
+ |---------------------------------- """ .stripMargin
24
+
25
+ assert(! owner.toLowerCase.contains(" box" ), s " Boxing instruction discovered in: \n $error" )
26
+ assert(! name.toLowerCase.contains(" box" ), s " Boxing instruction discovered in: \n $error" )
27
+ case _ => ()
28
+ }
29
+
15
30
@ Test def specializeParentIntToInt = {
16
31
val source = """
17
32
|class Foo extends Function1[Int, Int] {
@@ -50,4 +65,30 @@ class SpecializeFunction1Tests extends DottyBytecodeTest {
50
65
)
51
66
}
52
67
}
68
+
69
+ @ Test def checkBoxingIntToInt = {
70
+ val source =
71
+ """ |object Test {
72
+ | class Func1 extends Function1[Int, Int] {
73
+ | def apply(i: Int) = i + 1
74
+ | }
75
+ |
76
+ | (new Func1)(1)
77
+ |}""" .stripMargin
78
+
79
+ checkBCode(source) { dir =>
80
+ import scala .collection .JavaConverters ._
81
+ val clsIn = dir.lookupName(" Test$.class" , directory = false ).input
82
+ val clsNode = loadClassNode(clsIn)
83
+ assert(clsNode.name == " Test$" , s " inspecting wrong class: ${clsNode.name}" )
84
+
85
+ clsNode.methods.asScala
86
+ .find(_.name == " <init>" )
87
+ .map { m =>
88
+ checkForBoxing(instructionsFromMethod(m), source)
89
+ }
90
+ .getOrElse(assert(false , " Could not find constructor for object `Test`" ))
91
+ }
92
+
93
+ }
53
94
}
0 commit comments