JVM: enable indy lambdas in some tests explicitly

To simplify enabling of indy lambdas by default.
This commit is contained in:
Alexander Udalov
2023-04-24 22:58:18 +02:00
committed by Space Team
parent cd9209a7ee
commit 4d7506bae3
18 changed files with 89 additions and 16 deletions
@@ -1,6 +1,7 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
// LAMBDAS: CLASS
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
@@ -0,0 +1,27 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
// LAMBDAS: INDY
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 1 java/lang/invoke/LambdaMetafactory
// ^ Since indy for SAM types with contravariant projections is disabled (see genericWithInProjection.kt), the bytecode in this test is
// suboptimal. The lambda is generated via invokedynamic LambdaMetafactory and then wrapped into an instance of Cmp.
// The optimal way would be to generate the Cmp instance via invokedynamic LambdaMetafactory directly.
fun interface Cmp<T> {
fun compare(a: T, b: T): Int
}
fun <T> foo(comparator: Cmp<in T>, a: T, b: T) = comparator.compare(a, b)
fun bar(x: Int, y: Int) = foo({ a, b -> a - b}, x, y)
fun box(): String {
val t = bar(42, 117)
if (t != -75)
return "Failed: t=$t"
return "OK"
}