tseisel
09/01/2020, 2:28 PMsealed class LoadRequest<out T> {
object Pending : LoadRequest<Nothing>()
class Success<T>(val data: T) : LoadRequest<T>()
class Failure(val error: Throwable) : LoadRequest<Nothing>()
}
When writing the following code with Kotlin 1.4, I have a warning telling me that the following cast is unnecessary:
val someFlow: Flow<String> = ...
val requestFlow: Flow<LoadRequest<String>> = someFlow
.map { LoadRequest.Success(it) as LoadRequest<String> }
^^^^^^^^^^^^^^^^^^^^^^
.onStart { emit(LoadRequest.Pending) }
.catch { emit(LoadRequest.Failure(it) }
But removing it makes onStart
and catch
incompatible with the type of the returned Flow
.
Is this some new compiler inference bug ?