// WITH_STDLIB // SKIP_TXT fun test() { foo( flow { emit(0) } ) { it.collect {} } // 0. Initial // W <: Any / declared upper bound // FlowCollector.() -> Unit <: FlowCollector.() -> Unit / from Argument { emit(0) } // F <: Any / declared upper bound // Flow <: F / from Argument flow { emit(0) } // Scope.(F) -> Unit -> Scope.(F) -> Unit / from Argument { it.collect() } // 1. after analyze for { emit(0 } // Unit <: Unit / from Lambda argument, probably { emit(0) } // Int <: W / from For builder inference call // Flow <: F / from For builder inference call // 2. after analyze for { it.collect {} } // Unit <: Unit / from Lambda argument, probably { it.collect {} } // Flow<*> <: F / from For builder inference call // ERROR_TYPE <: W / from For builder inference call } fun foo( bar: F, block: Scope.(F) -> Unit ) {} @OptIn(kotlin.experimental.ExperimentalTypeInference::class) fun flow(@BuilderInference block: FlowCollector.()->Unit): Flow { val collector = FlowCollectorImpl() collector.block() return object : Flow { override fun collect(collector: FlowCollector) { } } } class Scope interface Flow { fun collect(collector: FlowCollector) } fun interface FlowCollector { fun emit(value: I) } class FlowCollectorImpl : FlowCollector { override fun emit(value: C) {} } fun Flow<*>.collect() {}