Inspectopedia
 
2024.3

Ambiguous coroutineContext due to CoroutineScope receiver of suspend function

Warning
New
Last modified: 03 December 2024

Reports calls and accesses of CoroutineScope extensions or members inside suspend functions with CoroutineScope receiver.

When a function is suspend and has CoroutineScope receiver, it has ambiguous access to CoroutineContext via kotlin.coroutines.coroutineContext and via CoroutineScope.coroutineContext, and two these contexts are different in general.

To improve this situation, one can wrap suspicious call inside coroutineScope { ... } or get rid of CoroutineScope function receiver.