Use initial system for completion if common one is effectively empty

Otherwise we can get unsubstituted type variables as expected types and
 then write wrong information for assertions

 #KT-41470 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-08-28 15:11:52 +03:00
parent bb18203ae6
commit 23f87d413a
9 changed files with 87 additions and 8 deletions
@@ -0,0 +1,38 @@
// WITH_RUNTIME
@file:OptIn(kotlin.experimental.ExperimentalTypeInference::class)
interface Flow<out T> {
fun collect(collector: FlowCollector<T>)
}
interface FlowCollector<in T> {
fun emit(value: T)
}
fun <T> flow(block: FlowCollector<T>.() -> Unit): Flow<T> =
object : Flow<T> {
override fun collect(collector: FlowCollector<T>) = collector.block()
}
fun <T> Flow<T>.collect(action: (value: T) -> Unit): Unit =
collect(object : FlowCollector<T> {
override fun emit(value: T) = action(value)
})
fun <T, R> Flow<T>.transform(@BuilderInference transform: FlowCollector<R>.(T) -> Unit): Flow<R> =
flow { collect { transform(it) } }
fun <T, R> Flow<T>.map(transform: (T) -> R): Flow<R> =
transform { emit(transform(it)) }
var result: Any? = "not null"
fun main() {
flow<Int> { emit(1) }.map { null }.collect { result = it }
}
fun box(): String {
main()
return if (result == null) "OK" else "fail: $result"
}