JS: support SAM conversion
The SAM adapter is generate on declaration site. This is different from the JVM approach. `external fun interface` is banned for now. Reusing interface declaration for the adapter is a hack which reduces code size and makes importing/exporting the adapter effortless.
This commit is contained in:
+16
-2
@@ -1,11 +1,11 @@
|
||||
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS, JS_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// WITH_COROUTINES
|
||||
// WITH_RUNTIME
|
||||
|
||||
import helpers.*
|
||||
import kotlin.coroutines.startCoroutine
|
||||
import kotlin.coroutines.*
|
||||
|
||||
fun interface SuspendRunnable {
|
||||
suspend fun invoke()
|
||||
@@ -17,11 +17,25 @@ fun run(r: SuspendRunnable) {
|
||||
|
||||
var result = "initial"
|
||||
|
||||
var resumingCallback: () -> Unit = {}
|
||||
|
||||
suspend fun bar() {
|
||||
// Generate proper state machine
|
||||
suspendCoroutine<Unit> { cont ->
|
||||
resumingCallback = {
|
||||
cont.resume(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
result = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
run(::bar)
|
||||
|
||||
if (result != "initial") return "fail"
|
||||
|
||||
resumingCallback()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user