FIC: add codegen tests, adapt previously tests for SAMs
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +NewInference +FunctionInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||
|
||||
fun interface KRunnable {
|
||||
fun invoke()
|
||||
}
|
||||
|
||||
fun test(a: Any?) {
|
||||
a as () -> Unit
|
||||
KRunnable(a).invoke()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
test {
|
||||
result = "OK"
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// !LANGUAGE: +NewInference +FunctionInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun interface MyRunnable {
|
||||
fun invoke()
|
||||
}
|
||||
|
||||
class A {
|
||||
inline fun doWork(noinline job: () -> Unit) {
|
||||
MyRunnable(job).invoke()
|
||||
}
|
||||
|
||||
fun doNoninlineWork(job: () -> Unit) {
|
||||
MyRunnable(job).invoke()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = false
|
||||
A().doWork { result = true }
|
||||
if (!result) return "Fail 1"
|
||||
|
||||
result = false
|
||||
A().doNoninlineWork { result = true }
|
||||
if (!result) return "Fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// !LANGUAGE: +NewInference +FunctionInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun interface KRunnable {
|
||||
fun invoke()
|
||||
}
|
||||
|
||||
fun isNull(r: KRunnable?): Boolean {
|
||||
if (r == null) return true
|
||||
r.invoke()
|
||||
return false
|
||||
}
|
||||
|
||||
fun nullableFun(fromNull: Boolean): (() -> Unit)? =
|
||||
if (fromNull) null else {{}}
|
||||
|
||||
fun box(): String {
|
||||
if (!isNull(nullableFun(true))) return "Fail 1"
|
||||
if (isNull(nullableFun(false))) return "Fail 2"
|
||||
if (!isNull(null)) return "Fail 3"
|
||||
if (isNull {}) return "Fail 4"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// !LANGUAGE: +NewInference +FunctionInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun interface Fn<T, R> {
|
||||
fun run(s: String, i: Int, t: T): R
|
||||
}
|
||||
|
||||
class J {
|
||||
fun runConversion(f1: Fn<String, Int>, f2: Fn<Int, String>): Int {
|
||||
return f1.run("Bar", 1, f2.run("Foo", 42, 239))
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val j = J()
|
||||
var x = ""
|
||||
|
||||
val fsi = object : Fn<String, Int> {
|
||||
override fun run(s: String, i: Int, t: String): Int {
|
||||
x += "$s$i$t "
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
val fis = object : Fn<Int, String> {
|
||||
override fun run(s: String, i: Int, t: Int): String {
|
||||
x += "$s$i$t "
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
val r1 = j.runConversion(fsi) { s, i, ti -> x += "L$s$i$ti "; "L$s"}
|
||||
val r2 = j.runConversion({ s, i, ts -> x += "L$s$i$ts"; i }, fis)
|
||||
|
||||
if (r1 != 1) return "fail r1: $r1"
|
||||
if (r2 != 1) return "fail r2: $r2"
|
||||
|
||||
if (x != "LFoo42239 Bar1LFoo Foo42239 LBar1Foo") return x
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// !LANGUAGE: +NewInference +FunctionInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun interface KRunnable {
|
||||
fun invoke()
|
||||
}
|
||||
|
||||
fun runTwice(r: KRunnable) {
|
||||
r.invoke()
|
||||
r.invoke()
|
||||
}
|
||||
|
||||
class A() {
|
||||
fun f() {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var x = 0
|
||||
runTwice({ x++; A() }()::f)
|
||||
if (x != 1) return "Fail"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user