Make createCoroutine return a safe continuation
#KT-15718 Fixed
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
import kotlin.coroutines.experimental.*
|
||||
import kotlin.coroutines.experimental.intrinsics.*
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
val x = c.createCoroutine(EmptyContinuation)
|
||||
|
||||
x.resume(Unit)
|
||||
x.resume(Unit)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
|
||||
try {
|
||||
builder {
|
||||
result = "OK"
|
||||
}
|
||||
} catch (e: IllegalStateException) {
|
||||
return result
|
||||
}
|
||||
|
||||
return "fail: $result"
|
||||
}
|
||||
@@ -15,9 +15,14 @@ fun builder1(c: suspend () -> Unit) {
|
||||
|
||||
fun builder2(c: suspend () -> Unit) {
|
||||
val continuation = c.createCoroutine(EmptyContinuation)
|
||||
val declaredField = continuation.javaClass.superclass.getDeclaredField("label")
|
||||
|
||||
val delegateField = continuation.javaClass.getDeclaredField("delegate")
|
||||
delegateField.setAccessible(true)
|
||||
val originalContinuation = delegateField.get(continuation)
|
||||
|
||||
val declaredField = originalContinuation.javaClass.superclass.getDeclaredField("label")
|
||||
declaredField.setAccessible(true)
|
||||
declaredField.set(continuation, -3)
|
||||
declaredField.set(originalContinuation, -3)
|
||||
continuation.resume(Unit)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user