[FIR] Report more occurrences of NON_LOCAL_RETURN_NOT_ALLOWED

When an inline lambda is invoked or passed to another inline function,
make sure non-local returns are allowed by all surrounding declarations.
Otherwise, NON_LOCAL_RETURN_NOT_ALLOWED must be reported.

^KT-59884 Fixed
^KT-55319 Fixed
This commit is contained in:
Brian Norman
2023-10-31 11:25:39 -05:00
committed by Space Team
parent b3d33aee19
commit 3327bed5bd
19 changed files with 84 additions and 188 deletions
@@ -18,10 +18,10 @@ inline fun test(c: () -> Unit) {
c()
val o = object : Runnable {
override fun run() {
c()
<!NON_LOCAL_RETURN_NOT_ALLOWED!>c<!>()
}
}
val l = { c() }
val l = { <!NON_LOCAL_RETURN_NOT_ALLOWED!>c<!>() }
<!USAGE_IS_NOT_INLINABLE!>c<!>.startCoroutine(EmptyContinuation)
}
@@ -1,40 +0,0 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE -UNUSED_PARAMETER
// SKIP_TXT
// WITH_COROUTINES
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
import helpers.*
interface SuspendRunnable {
suspend fun run()
}
// Function is NOT suspend
// parameter is inline
// parameter is suspend
// Block is NOT allowed to be called inside the body of owner inline function
// Block is NOT allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls possible inside lambda matching to the parameter
inline fun test(<!INLINE_SUSPEND_FUNCTION_TYPE_UNSUPPORTED!>c: suspend () -> Unit<!>) {
<!ILLEGAL_SUSPEND_FUNCTION_CALL!>c<!>()
val o = object: SuspendRunnable {
override suspend fun run() {
c()
}
}
val l: suspend () -> Unit = { c() }
<!USAGE_IS_NOT_INLINABLE!>c<!>.startCoroutine(EmptyContinuation)
}
fun builder(c: suspend () -> Unit) {}
suspend fun calculate() = "OK"
fun box() {
test {
calculate()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE -UNUSED_PARAMETER
// SKIP_TXT
@@ -16,10 +16,10 @@ suspend inline fun test(c: () -> Unit) {
c()
val o = object: Runnable {
override fun run() {
c()
<!NON_LOCAL_RETURN_NOT_ALLOWED!>c<!>()
}
}
val l = { c() }
val l = { <!NON_LOCAL_RETURN_NOT_ALLOWED!>c<!>() }
<!USAGE_IS_NOT_INLINABLE!>c<!>.startCoroutine(EmptyContinuation)
}
@@ -21,10 +21,10 @@ suspend inline fun test(c: suspend () -> Unit) {
c()
val o = object: SuspendRunnable {
override suspend fun run() {
c()
<!NON_LOCAL_RETURN_NOT_ALLOWED!>c<!>()
}
}
val l: suspend () -> Unit = { c() }
val l: suspend () -> Unit = { <!NON_LOCAL_RETURN_NOT_ALLOWED!>c<!>() }
<!USAGE_IS_NOT_INLINABLE!>c<!>.startCoroutine(EmptyContinuation)
}