Files
kotlin-fork/compiler/testData/diagnostics/tests/inference/builderInference/kt53422.kt
T
Ilya Kirillov 1bbcae5ed2 [FIR] fix resolve contract violation from scopes
We cannot call lazy resolve to STATUS phase from scopes as scopes may be accessed on a STATUS phase or earlier

^KT-54890
^KTIJ-23587 fixed
2023-01-13 21:32:51 +00:00

57 lines
1.6 KiB
Kotlin
Vendored

// WITH_STDLIB
// SKIP_TXT
fun test() {
foo(
flow { emit(0) }
) <!BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION!>{ <!BUILDER_INFERENCE_STUB_RECEIVER!>it<!>.collect <!TOO_MANY_ARGUMENTS!>{}<!> }<!>
// 0. Initial
// W <: Any / declared upper bound
// FlowCollector<W>.() -> Unit <: FlowCollector<W>.() -> Unit / from Argument { emit(0) }
// F <: Any / declared upper bound
// Flow<W> <: F / from Argument flow { emit(0) }
// Scope<F>.(F) -> Unit -> Scope<F>.(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<Int> <: 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 <F : Any> foo(
bar: F,
block: Scope<F>.(F) -> Unit
) {}
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
fun <W> flow(@BuilderInference block: FlowCollector<W>.()->Unit): Flow<W> {
val collector = FlowCollectorImpl<W>()
collector.block()
return object : Flow<W> {
override fun collect(collector: FlowCollector<W>) {
}
}
}
class Scope<S>
interface Flow<out O> {
fun collect(collector: FlowCollector<O>)
}
fun interface FlowCollector<in I> {
fun emit(value: I)
}
class FlowCollectorImpl<C> : FlowCollector<C> {
override fun emit(value: C) {}
}
fun Flow<*>.collect() {}