Reports potentially problematic implicit CoroutineScope receiver access from within a suspending context.
When a suspend function or lambda captures an implicit CoroutineScope receiver from the outer context, it might lead to unexpected behavior.
This is because the captured scope might be canceled or completed while the suspend function is still running.
The inspection detects situations where code implicitly accesses a CoroutineScope receiver from inside a suspend function or lambda,
creating a potentially dangerous dependency on the outer scope.
Example:
class MyClass {
fun CoroutineScope.launchJobs() {
launch { // OK: direct usage in the extension function
doSomething()
}
suspendingFunction { // Warning: Suspicious implicit 'CoroutineScope' receiver access
launch { // The launch call uses implicit CoroutineScope from the outer context
doSomethingElse()
}
}
}
}
Options:
To fix this issue, you can:
this@receiverLabel.method()coroutineScope { } builder to create a child scope that is tied to the suspend function's lifecycle