Fix suspend function with default argument
In JS BE, fix translation of suspend function with default argument inherited from interface. See KT-16658
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
fun box(): String {
|
||||
async {
|
||||
O.foo()
|
||||
O.foo("second")
|
||||
}
|
||||
while (!finished) {
|
||||
result += "--;"
|
||||
proceed()
|
||||
}
|
||||
|
||||
finished = false
|
||||
asyncSuspend {
|
||||
O.foo()
|
||||
O.foo("second")
|
||||
}
|
||||
while (!finished) {
|
||||
result += "--;"
|
||||
proceed()
|
||||
}
|
||||
|
||||
val expected = "before(first);--;after(first);before(second);--;after(second);--;done;"
|
||||
if (result != expected + expected) return "fail: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
interface I {
|
||||
suspend fun foo(x: String = "first")
|
||||
}
|
||||
|
||||
object O : I {
|
||||
override suspend fun foo(x: String) {
|
||||
result += "before($x);"
|
||||
sleep()
|
||||
result += "after($x);"
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun sleep(): Unit = suspendCoroutine { c ->
|
||||
proceed = { c.resume(Unit) }
|
||||
}
|
||||
|
||||
fun async(f: suspend () -> Unit) {
|
||||
f.startCoroutine(object : Continuation<Unit> {
|
||||
override fun resume(x: Unit) {
|
||||
proceed = {
|
||||
result += "done;"
|
||||
finished = true
|
||||
}
|
||||
}
|
||||
override fun resumeWithException(x: Throwable) {}
|
||||
override val context = EmptyCoroutineContext
|
||||
})
|
||||
}
|
||||
|
||||
fun asyncSuspend(f: suspend () -> Unit) {
|
||||
val coroutine = f.createCoroutine(object : Continuation<Unit> {
|
||||
override fun resume(x: Unit) {
|
||||
proceed = {
|
||||
result += "done;"
|
||||
finished = true
|
||||
}
|
||||
}
|
||||
override fun resumeWithException(x: Throwable) {}
|
||||
override val context = EmptyCoroutineContext
|
||||
})
|
||||
coroutine.resume(Unit)
|
||||
}
|
||||
|
||||
var result = ""
|
||||
var proceed: () -> Unit = { }
|
||||
var finished = false
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
@kotlin.Metadata
|
||||
public final class CoroutineUtilKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method handleExceptionContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.experimental.Continuation
|
||||
public final static @org.jetbrains.annotations.NotNull method handleResultContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.experimental.Continuation
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public class EmptyContinuation {
|
||||
public final static field Companion: EmptyContinuation.Companion
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.experimental.CoroutineContext
|
||||
inner class EmptyContinuation/Companion
|
||||
public @synthetic.kotlin.jvm.GeneratedByJvmOverloads method <init>(): void
|
||||
public method <init>(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.experimental.CoroutineContext): void
|
||||
public synthetic method <init>(p0: kotlin.coroutines.experimental.CoroutineContext, p1: int, p2: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.experimental.CoroutineContext
|
||||
public method resume(@org.jetbrains.annotations.Nullable p0: java.lang.Object): void
|
||||
public method resumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final static class EmptyContinuation/Companion {
|
||||
inner class EmptyContinuation/Companion
|
||||
private method <init>(): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public interface I {
|
||||
inner class I/DefaultImpls
|
||||
public abstract @org.jetbrains.annotations.Nullable method foo(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.experimental.Continuation): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class I/DefaultImpls {
|
||||
inner class I/DefaultImpls
|
||||
public synthetic static method foo$default(p0: I, p1: java.lang.String, p2: kotlin.coroutines.experimental.Continuation, p3: int, p4: java.lang.Object): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class O {
|
||||
public final static field INSTANCE: O
|
||||
private method <init>(): void
|
||||
public @org.jetbrains.annotations.Nullable method foo(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.experimental.Continuation): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class OverrideDefaultArgumentKt {
|
||||
private static field finished: boolean
|
||||
private static @org.jetbrains.annotations.NotNull field proceed: kotlin.jvm.functions.Function0
|
||||
private static @org.jetbrains.annotations.NotNull field result: java.lang.String
|
||||
public final static method async(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void
|
||||
public final static method asyncSuspend(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method getFinished(): boolean
|
||||
public final static @org.jetbrains.annotations.NotNull method getProceed(): kotlin.jvm.functions.Function0
|
||||
public final static @org.jetbrains.annotations.NotNull method getResult(): java.lang.String
|
||||
public final static method setFinished(p0: boolean): void
|
||||
public final static method setProceed(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): void
|
||||
public final static method setResult(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
|
||||
public final static @org.jetbrains.annotations.Nullable method sleep(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.experimental.Continuation): java.lang.Object
|
||||
}
|
||||
Reference in New Issue
Block a user