Files
kotlin-fork/compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

30 lines
581 B
Kotlin
Vendored

// WITH_STDLIB
// Issue: KT-36371
import kotlin.experimental.ExperimentalTypeInference
class Foo(val string: String? = null)
class Builder<T> {
private var resolver: ((Foo) -> T)? = null
fun build() = resolver!!
fun resolve(resolver: (Foo) -> T) {
this.resolver = resolver
}
}
@OptIn(ExperimentalTypeInference::class)
fun <T> build(@BuilderInference configure: Builder<T>.() -> Unit) =
Builder<T>().apply(configure).build()
fun box(): String {
val resolver = build {
resolve { it.string }
}
resolver(Foo())
return "OK"
}