PSI2IR KT-49526 function reference type approximation hack

This commit is contained in:
Dmitry Petrov
2021-12-17 16:18:11 +03:00
committed by Space
parent 9c0ea11c1b
commit 976998b56c
21 changed files with 360 additions and 1 deletions
@@ -0,0 +1,12 @@
// IGNORE_BACKEND_FIR: JVM_IR
// FIR_STATUS: callable reference type approximation hack not implemented
// WITH_STDLIB
// CHECK_BYTECODE_LISTING
inline fun <T> useRef(value: T, f: (T) -> Boolean) = f(value)
fun box(): String {
val chars = listOf('a') + "-"
return if (useRef('a', chars::contains)) "OK" else "Failed"
}
@@ -0,0 +1,6 @@
@kotlin.Metadata
public final class Kt49526Kt {
// source: 'kt49526.kt'
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static method useRef(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function1): boolean
}
@@ -0,0 +1,35 @@
// IGNORE_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// IGNORE_BACKEND_FIR: JVM_IR
// FIR_STATUS: LambdaConversionException: Type mismatch for lambda argument 1: class java.lang.Object is not convertible to interface I1
// 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
}
@@ -0,0 +1,20 @@
// IGNORE_BACKEND_FIR: JVM_IR
// FIR_STATUS: callable reference type approximation hack not implemented
fun <T> id(x: T): T = x
fun <T> intersect(x: T, y: T): T = x
interface I1
interface I2
class C1 : I1, I2 {
override fun toString() = "OK"
}
class C2 : I1, I2
fun box() =
intersect(C1(), C2())
.let(::id)
.toString()
@@ -0,0 +1,12 @@
// IGNORE_BACKEND_FIR: JVM_IR
// FIR_STATUS: callable reference type approximation hack not implemented
// WITH_STDLIB
inline fun <T> useRef(value: T, f: (T) -> Boolean) = f(value)
fun box(): String {
val chars = listOf('a') + "-"
val ref = chars::contains
return if (ref('a')) "OK" else "Failed"
}