Inspectopedia 2025.3 Help

Suspicious implicit 'CoroutineScope' receiver access

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.

Such code can be prone to violating the rules of Structured Concurrency, even though it might look deceptively well-structured.

This can lead to incorrect behaviors when handling errors, cancelling computations, or managing lifetimes.

A typical example:

fun processFlow(flow: Flow<String>) { runBlocking { flow.collectLatest { // launched on this@runBlocking CoroutineScope launch { longProcessing(value) } } } } suspend fun longProcessing(value: String) { ... }

In the example above, the launch { ... } call launches coroutines in the implicit CoroutineScope from the outer runBlocking call.

Because of this, collectLatest would not be able to cancel those coroutines when it needs to.

This inspection will detect that launch is called on a CoroutineScope which is captured from the outside of the current suspending lambda (i.e. collectLatest's body).

For more information about this particular problem, see this GitHub Issue.

Possible solutions:

To fix this issue, you can:

  • Use coroutineScope { ... } builder to create a child scope that is tied to the suspend function's lifecycle

  • Rearrange the code so that the implicit CoroutineScope comes from the current syntactical context

In case you are sure that the code is correct, you can explicitly specify the receiver to make your intention clear. In the example above, that would be this@runBlocking.launch { ... }. Note, however, that in this case the semantics of the code won't change.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

SuspiciousImplicitCoroutineScopeReceiverAccess
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Kotlin | Coroutine inspections

Inspection ID: SuspiciousImplicitCoroutineScopeReceiverAccess

Inspection options

Here you can find the description of settings available for the Suspicious implicit 'CoroutineScope' receiver access inspection, and the reference of their default values.

Detect receivers of 'CoroutineScope' subtypes

Option ID:

detectCoroutineScopeSubtypes

Default value:

Not selected

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection SuspiciousImplicitCoroutineScopeReceiverAccess

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.3, Qodana for JVM 2025.3,

Last modified: 03 December 2025