[K/JS] Reset exceptionState inside coroutines with a finally block ^KT-58685 Fixed

This commit is contained in:
Artem Kobzar
2023-09-12 15:18:16 +00:00
committed by Space Team
parent 752ea6fd98
commit 7bc521ab92
8 changed files with 86 additions and 6 deletions
+46
View File
@@ -0,0 +1,46 @@
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
var isLocked = false
fun builder(c: suspend () -> Unit) {
c.startCoroutine(object : Continuation<Unit> {
override val context = EmptyCoroutineContext
override fun resumeWith(result: Result<Unit>) {}
})
}
private suspend fun lock() {
isLocked = true
}
private fun unlock() {
if (isLocked) {
isLocked = false
} else {
throw IllegalStateException("Not locked")
}
}
private suspend inline fun <T> withLock(block: () -> T): T {
lock()
try {
return block()
} finally {
unlock()
}
}
fun box(): String {
var error: Exception? = null
builder {
try {
withLock {}
throw Exception("seems fine")
} catch (e: Exception) {
error = e
}
}
return if (error !is IllegalStateException) "OK" else "fail"
}