IR: check whether local declarations need to throw after Nothing return
^KT-48982 Fixed
This commit is contained in:
@@ -5,12 +5,14 @@ import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
class Success : RuntimeException()
|
||||
|
||||
suspend fun suspendThenThrow(): Nothing {
|
||||
suspendCoroutineUninterceptedOrReturn<Unit> {
|
||||
it.resume(Unit)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
throw RuntimeException()
|
||||
throw Success()
|
||||
}
|
||||
|
||||
suspend fun foo(x: Int = 1): Nothing = suspendThenThrow()
|
||||
@@ -26,9 +28,20 @@ class C : I by (object : I {
|
||||
var result = ""
|
||||
|
||||
fun box(): String {
|
||||
var counter = 0
|
||||
suspend {
|
||||
try { foo() } catch (e: RuntimeException) { result += "O" }
|
||||
try { C().bar() } catch (e: RuntimeException) { result += "K" }
|
||||
// 1. foo$default is a bridge to foo, should not throw after foo returns
|
||||
try { foo() } catch (e: Success) { counter++ }
|
||||
// 2. C.bar is a delegation to another method, so same
|
||||
try { C().bar() } catch (e: Success) { counter++ }
|
||||
// 3. object.foo$default is the same as 1 but in a local object
|
||||
try {
|
||||
object {
|
||||
suspend fun foo(x: Int = 1): Nothing = suspendThenThrow()
|
||||
}.foo()
|
||||
} catch (e: Success) { counter++ }
|
||||
// 4. this point should be reached exactly once
|
||||
counter++
|
||||
}.startCoroutine(EmptyContinuation)
|
||||
return result
|
||||
return if (counter == 4) "OK" else "counter incremented $counter times"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user