Files
kotlin-fork/compiler/testData/codegen/box/invokedynamic/sam/specializedGenerics/genericWithInProjection.kt
T
Denis.Zharkov 05ca001310 FIR2IR: Repeat the K1 behavior: SAM conversion with 'in' projection
It would be more consistently to prohibit the behavior from the unmuted
test (see KT-52428), but it was decided to postpone the breaking change.

Unfortunately, it didn't work to make a test where for computing
star projections we would need to substitute other type parameters
because effectively, it's not allowed to have SAM conversion when
star projections/wildcard is based on a type parameter which bounds
use other type parameters.

^KT-53552 In progress
2023-02-20 14:54:09 +00:00

24 lines
548 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 java/lang/invoke/LambdaMetafactory
// TODO: restore indy for SAM types with contravariant projections. See KT-52428 for more info.
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"
}