Fix processing of uninitialized instances for coroutines
The problem is that code in the attached test led to VerifyError at runtime because the Bar's uninitialized instance created in 'map' was being stored to the field (leaked from the JVM point of view). The actual problem was that after repeating visiting of NEW operation we used to drop the set of already visited copy usages. For clarification see the comment before 'processUninitializedStores' #KT-15016 Fixed
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.coroutines.intrinsics.SUSPENDED_MARKER
|
||||
import kotlin.coroutines.intrinsics.suspendCoroutineOrReturn
|
||||
import kotlin.coroutines.startCoroutine
|
||||
|
||||
class Bar(val x: Any)
|
||||
inline fun Any.map(transform: (Any) -> Any) {
|
||||
when (this) {
|
||||
is Foo -> Bar(transform(value))
|
||||
}
|
||||
}
|
||||
|
||||
class Foo(val value: Any) {
|
||||
companion object {
|
||||
inline fun of(f: () -> Unit): Any = try {
|
||||
Foo(f())
|
||||
} catch(ex: Exception) {
|
||||
Foo(Unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
|
||||
x.resume("OK")
|
||||
SUSPENDED_MARKER
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
|
||||
builder {
|
||||
Foo.of {
|
||||
|
||||
}.map {
|
||||
result = suspendHere()
|
||||
Unit
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user