A suspend function extends CoroutineScope, mixing two ways to run concurrent work

tx0/kotlin:suspend-coroutine-scope-extensionrecommendedwarningreliability/concurrencydepth fastsmell, concurrency

What it finds

suspend fun CoroutineScope.load(): a function that suspends already runs in a coroutine and can open a scope with coroutineScope, while an extension on CoroutineScope is meant to start coroutines and return at once. Doing both makes it unclear whether the function waits for the coroutines it starts, and this hides the caller's context.

From the rule's source, suspend_scope_extension.rs.

Example from the rule's tests
import kotlinx.coroutines.* suspend fun CoroutineScope.loadAll() {tx0 reports: loadAll both suspends and extends CoroutineScope    launch { }} fun CoroutineScope.startAll() = launch { } suspend fun loadEach() = coroutineScope { launch { } }
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:suspend-coroutine-scope-extension" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:suspend-coroutine-scope-extension] reason="..."

tx0 explain tx0/kotlin:suspend-coroutine-scope-extension shows the same in the terminal. Found a false positive? Report it.