Files
kotlin-fork/compiler/testData/codegen/box/builderInference/issues/kt60447a.kt
T
2023-12-05 18:15:52 +00:00

34 lines
998 B
Kotlin
Vendored

// ISSUE: KT-60447
// IGNORE_LIGHT_ANALYSIS
// IGNORE_BACKEND: ANY
// REASON: red code (see corresponding diagnostic test)
fun box(): String {
val buildee = build {
class ConcreteType
class TargetType {
fun consumeConcreteType(value: ConcreteType) {}
}
setTypeVariableProducerFunction { TargetType() }
setTypeVariableConsumerFunction { it.consumeConcreteType(ConcreteType()) }
}
val targetType = buildee.typeVariableProducer()
buildee.typeVariableConsumer(targetType)
return "OK"
}
class Buildee<TV> {
var typeVariableConsumer: (TV) -> Unit = {}
var typeVariableProducer: () -> TV = { null!! }
fun setTypeVariableConsumerFunction(consumer: (TV) -> Unit) { typeVariableConsumer = consumer }
fun setTypeVariableProducerFunction(producer: () -> TV) { typeVariableProducer = producer }
}
fun <PTV> build(instructions: Buildee<PTV>.() -> Unit): Buildee<PTV> {
return Buildee<PTV>().apply(instructions)
}