@@ -141,4 +141,77 @@ class SpecializeFunctionsTests extends DottyBytecodeTest {
141
141
assertBoxing(" <init>" , findClass(" Test$" , dir).methods)
142
142
}
143
143
}
144
+
145
+ @ Test def multipleParentsNoBoxing = {
146
+ implicit val source : String =
147
+ """ |object Test {
148
+ | class Func01 extends Function0[Int] with Function1[Int, Int] {
149
+ | def apply(): Int = 0
150
+ | def apply(x: Int): Int = x
151
+ | }
152
+ | (new Func01: Function0[Int])()
153
+ | (new Func01: Function1[Int, Int])(1)
154
+ |}""" .stripMargin
155
+
156
+ checkBCode(source) { dir =>
157
+ assertNoBoxing(" <init>" , findClass(" Test$" , dir).methods)
158
+ }
159
+ }
160
+
161
+ @ Test def multipleLevelInheritanceNoBoxing = {
162
+ implicit val source : String =
163
+ """ |object Test {
164
+ | class Func1[T](fn: T => Int) extends Function1[T, Int] {
165
+ | def apply(x: T): Int = fn(x)
166
+ | }
167
+ | class Fn extends Func1(identity[Int])
168
+ | (new Fn: Function1[Int, Int])(123)
169
+ |}""" .stripMargin
170
+
171
+ checkBCode(source) { dir =>
172
+ assertNoBoxing(" <init>" , findClass(" Test$" , dir).methods)
173
+ }
174
+ }
175
+
176
+ @ Test def lambdaNoBoxing1 = {
177
+ implicit val source : String =
178
+ """ |object Test {
179
+ | val fn = (x: Int) => x + 1
180
+ | fn(2)
181
+ |}""" .stripMargin
182
+
183
+ checkBCode(source) { dir =>
184
+ assertNoBoxing(" <init>" , findClass(" Test$" , dir).methods)
185
+ }
186
+ }
187
+
188
+ @ Test def lambdaNoBoxing2 = {
189
+ implicit val source : String =
190
+ """ |object Test {
191
+ | def fn[T, U, V](op0: T => U, op1: U => V): T => V = (x: T) => op1(op0(x))
192
+ | val f0: Int => Double = _.toDouble
193
+ | val f1: Double => Int = _.toInt
194
+ | val id = fn(f0, f1)
195
+ | id(2)
196
+ |}""" .stripMargin
197
+
198
+ checkBCode(source) { dir =>
199
+ assertNoBoxing(" <init>" , findClass(" Test$" , dir).methods)
200
+ }
201
+ }
202
+
203
+ @ Test def classWithFieldBoxing = {
204
+ implicit val source : String =
205
+ """ |object Test {
206
+ | class Func0[T](x: T) extends Function0[T] {
207
+ | def apply(): T = x
208
+ | }
209
+ | (new Func0(2): Function0[Int])()
210
+ |}""" .stripMargin
211
+
212
+ checkBCode(source) { dir =>
213
+ // Boxing happens because of the field of `Func0`.
214
+ assertBoxing(" <init>" , findClass(" Test$" , dir).methods)
215
+ }
216
+ }
144
217
}
0 commit comments