kotlin:S6311 raises a false-positive for Android ViewModel coroutines usage

Make sure to read this post before raising a thread here:

Then tell us:

class MyViewModel() : ViewModel() {

    private val _actions = MutableSharedFlow<Unit>()
    val actions: Flow<Unit> = _actions

    fun nonSuspendingFunction() {
        viewModelScope.launch {
            _actions.emit(Unit)
        }
    }
}

Hey Jonny,

Thanks for letting us know.

kotlin:S6311 has a bug currently, which causes it to raise an issue in cases such as the snippet you gave. There is a fix underway and it should be corrected by the next release.

1 Like