JVM_IR indy-SAM conversions: more cases

KT-44278 KT-26060 KT-42621
This commit is contained in:
Dmitry Petrov
2021-01-20 14:51:07 +03:00
parent 3140cca050
commit f30e25aa52
17 changed files with 383 additions and 57 deletions
@@ -0,0 +1,16 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface IntFun {
fun invoke(i: Int): Int
}
fun invoke1(intFun: IntFun) = intFun.invoke(1)
fun box(): String {
val test = invoke1(41::plus)
if (test != 42) return "Failed: $test"
return "OK"
}
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface KRunnable {
fun run()
}
fun runIt(r: KRunnable) {
r.run()
}
fun box(): String {
var test = "Failed"
runIt { test = "OK" }
return test
}
@@ -0,0 +1,13 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
class C(val test: String)
fun interface MakeC {
fun make(x: String): C
}
fun make(makeC: MakeC) = makeC.make("OK")
fun box() = make(::C).test
@@ -0,0 +1,11 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface IFoo<T> {
fun foo(x: T): T
}
fun foo(fs: IFoo<String>) = fs.foo("O")
fun box() = foo { "${it}K" }
@@ -0,0 +1,16 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface IFoo<T> {
fun foo(x: T): T
}
fun foo1(fs: IFoo<Int>) = fs.foo(1)
fun box(): String {
val t = foo1 { it + 41 }
if (t != 42) return "Failed: t=$t"
return "OK"
}
@@ -0,0 +1,22 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface KRunnable {
fun run()
}
fun runnable(kr: KRunnable) = kr
fun foo() {}
fun box(): String {
val foo1 = runnable(::foo)
val foo2 = runnable(::foo)
if (foo1 != foo2) {
return "Failed: foo1 != foo2"
}
return "OK"
}