IntelliJ (and dokka soon) shows a warning when usi...
# coroutines
h
IntelliJ (and dokka soon) shows a warning when using `suspend fun CoroutineScope.foo() { }`:
Ambiguous coroutineContext due to CoroutineScope receiver of suspend function
, because
CoroutineScope.coroutineContext
and
coroutineContext
. But why does coroutines-core itself use this construct? https://github.com/Kotlin/kotlinx.coroutines/blob/52cbf01c63c0737ee745ff08568f26385271a9ab/kotlinx-coroutines-core/common/src/Builders.common.kt#L50
e
launch is a scope builder
h
Yeah, I mean the lambda parameter too
e
it builds a new coroutine scope, which is both necessary within the lambda to perform more operations (launch etc.) and shadows and outer scope
h
But this also shadows
coroutineContext
from the suspend lambda and, according to the hint, you should use
coroutineScope
instead
e
yes it would be a possible API design to not provide a CoroutineScope receiver to the lambda. but this would be more error-prone
h
Okay, so it is save to use a
suspend CoroutineScope.() -> Unit
lambda, but is not safe to use
suspend fun CoroutineScope.foo()
and does not result into shadowing
coroutineContext
?