Use non-local return target instead of inline site in suspend function

return type coercion.
 #KT-43226 Fixed
This commit is contained in:
Ilmir Usmanov
2020-11-09 21:19:18 +01:00
parent d4f08018ce
commit fa42a6ba58
12 changed files with 165 additions and 33 deletions
@@ -60,6 +60,18 @@ class Test3 {
suspend fun test() = bar().s
}
class Test4 {
suspend fun <T> foo(value: T): T = value
suspend fun bar(): IC? {
run {
return foo(IC("OK"))
}
}
suspend fun test() = bar()!!.s
}
fun box(): String {
var result = "FAIL"
@@ -83,5 +95,13 @@ fun box(): String {
result = Test3().test()
}
if (result != "OK") return "FAIL 3 $result"
result = "FAIL 4"
builder {
result = Test4().test()
}
return result
}
@@ -67,6 +67,18 @@ class Test3 {
suspend fun test() = bar().s
}
class Test4 {
suspend fun <T> foo(value: T): T = value
suspend fun bar(): IC? {
run {
return foo(suspendMe())
}
}
suspend fun test() = bar()!!.s
}
fun box(): String {
var result = "FAIL"
@@ -93,5 +105,14 @@ fun box(): String {
}
c?.resume(IC("OK"))
if (result != "OK") return "FAIL 3 $result"
result = "FAIL 4"
builder {
result = Test4().test()
}
c?.resume(IC("OK"))
return result
}
@@ -71,6 +71,18 @@ class Test3 {
suspend fun test() = bar().s
}
class Test4 {
suspend fun <T> foo(value: T): T = value
suspend fun bar(): IC? {
run {
return foo(suspendMe())
}
}
suspend fun test() = bar()!!.s
}
fun box(): String {
builder {
Test1().test()
@@ -95,5 +107,12 @@ fun box(): String {
}
c?.resumeWithException(IllegalStateException("OK"))
if (result != "OK") return "FAIL 3 $result"
builder {
Test4().test()
}
c?.resumeWithException(IllegalStateException("OK"))
return result
}
@@ -0,0 +1,29 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
import kotlin.coroutines.*
suspend fun coroutineScope(c: suspend () -> Unit) {
c()
}
var counter = 0
suspend fun whatever() = coroutineScope {
repeat(10) { // repeat hides a loop, that plays a part in the compiler crash
run {
counter++
return@repeat // required to reproduce the crash
}
}
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {})
}
fun box(): String {
builder {
whatever()
}
return if (counter != 10) "FAIL $counter" else "OK"
}