JVM_IR indy-SAM conversions: inline funs and lambdas

KT-44278 KT-26060 KT-42621
This commit is contained in:
Dmitry Petrov
2021-01-26 15:30:41 +03:00
parent 4da2f3d9d4
commit 98b0c07b18
11 changed files with 191 additions and 0 deletions
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
// WITH_RUNTIME
// FILE: inlineFunInDifferentPackage.kt
import a.*
fun box() = test { k -> "O" + k }
// FILE: a.kt
package a
fun interface IFoo {
fun foo(k: String): String
}
fun fooK(iFoo: IFoo) = iFoo.foo("K")
inline fun test(crossinline lambda: (String) -> String) =
fooK { k -> lambda(k) }
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
// WITH_RUNTIME
fun interface IFoo {
fun foo()
}
fun foo(iFoo: IFoo) = iFoo.foo()
inline fun twice(fn: () -> Unit) {
fn()
fn()
}
fun box(): String {
var test = 0
twice {
foo { test += 1 }
}
if (test != 2)
return "Failed: test=$test"
return "OK"
}