Add CallChecker prohibiting non-local suspension calls
Effectively suspension point is local <=> return to relevant lambda is allowed in place
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
class Controller {
|
||||
suspend fun suspendHere(a: String, x: Continuation<Int>) {
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
suspend fun suspendHere(a: Int, x: Continuation<Int>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {}
|
||||
|
||||
fun test() {
|
||||
builder {
|
||||
suspendHere("")
|
||||
|
||||
with(A()) {
|
||||
suspendHere("")
|
||||
// This test checks that suspending functions
|
||||
// that are not from coroutine controller can't be called by suspending convention
|
||||
suspendHere(1<!NO_VALUE_FOR_PARAMETER!>)<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package
|
||||
|
||||
public fun builder(/*0*/ coroutine c: Controller.() -> kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Unit
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final suspend fun suspendHere(/*0*/ a: kotlin.Int, /*1*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class Controller {
|
||||
public constructor Controller()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final suspend fun suspendHere(/*0*/ a: kotlin.String, /*1*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Controller<T> {
|
||||
suspend fun suspendHere(x: Continuation<Int>) {
|
||||
}
|
||||
|
||||
suspend fun another(a: T, x: Continuation<Int>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> builder(coroutine c: Controller<T>.() -> Continuation<Unit>) { }
|
||||
|
||||
inline fun run(x: () -> Unit) {}
|
||||
|
||||
inline fun runCross(crossinline x: () -> Unit) {}
|
||||
|
||||
fun noinline(x: () -> Unit) {}
|
||||
|
||||
fun foo() {
|
||||
var result = 1
|
||||
builder<String> {
|
||||
suspendHere()
|
||||
another("")
|
||||
another(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>)
|
||||
|
||||
result += suspendHere()
|
||||
|
||||
run {
|
||||
result += suspendHere()
|
||||
run {
|
||||
suspendHere()
|
||||
}
|
||||
}
|
||||
|
||||
runCross {
|
||||
result += <!NON_LOCAL_SUSPENSION_POINT!>suspendHere<!>()
|
||||
runCross {
|
||||
<!NON_LOCAL_SUSPENSION_POINT!>suspendHere<!>()
|
||||
}
|
||||
}
|
||||
|
||||
noinline {
|
||||
result += <!NON_LOCAL_SUSPENSION_POINT!>suspendHere<!>()
|
||||
noinline {
|
||||
<!NON_LOCAL_SUSPENSION_POINT!>suspendHere<!>()
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
fun bar() {
|
||||
<!NON_LOCAL_SUSPENSION_POINT!>suspendHere<!>()
|
||||
}
|
||||
}
|
||||
|
||||
object : Any() {
|
||||
fun baz() {
|
||||
<!NON_LOCAL_SUSPENSION_POINT!>suspendHere<!>()
|
||||
}
|
||||
}
|
||||
|
||||
builder<Int> {
|
||||
suspendHere()
|
||||
|
||||
another(1)
|
||||
<!NON_LOCAL_SUSPENSION_POINT!>another<!>("")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> builder(/*0*/ coroutine c: Controller<T>.() -> kotlin.coroutines.Continuation<kotlin.Unit>): kotlin.Unit
|
||||
public fun foo(): kotlin.Unit
|
||||
public fun noinline(/*0*/ x: () -> kotlin.Unit): kotlin.Unit
|
||||
public inline fun run(/*0*/ x: () -> kotlin.Unit): kotlin.Unit
|
||||
public inline fun runCross(/*0*/ crossinline x: () -> kotlin.Unit): kotlin.Unit
|
||||
|
||||
public final class Controller</*0*/ T> {
|
||||
public constructor Controller</*0*/ T>()
|
||||
public final suspend fun another(/*0*/ a: T, /*1*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final suspend fun suspendHere(/*0*/ x: kotlin.coroutines.Continuation<kotlin.Int>): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user