Files
kotlin-fork/compiler/testData/codegen/box/callableReference/kt49526_sam.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

34 lines
600 B
Kotlin
Vendored

// IGNORE_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// JVM_IR it this case has an approximated type 'KFun<out Any>', which has a projected top-level argument.
fun <T> intersect(x: T, y: T): T = x
interface I1
interface I2
class C1 : I1, I2 {
override fun toString(): String = "OK"
}
class C2 : I1, I2
fun <T> T.k() = K<T>(this)
fun interface KFun<T> {
fun invoke(x: T)
}
class K<T>(private val x: T) {
fun with(kf: KFun<T>) {
kf.invoke(x)
}
}
fun box(): String {
var result = "Failed"
intersect(C1(), C2()).k().with { result = it.toString() }
return result
}