Files
kotlin-fork/compiler/testData/codegen/box/delegatedProperty/provideDelegate/kt39588.kt
T
Zalim Bashorov 6ebeeabe0f [Codegen tests] Fix the test (kt39588)
For negative case, throwing CCE, we already have the issue KT-8135
and dedicated tests:
* genericDelegateUncheckedCast1.kt
* genericDelegateUncheckedCast2.kt

Related issues: KT-8135 KT-39588 KT-48749 KT-49837
2022-05-05 15:47:54 +00:00

22 lines
926 B
Kotlin
Vendored

// WITH_STDLIB
import kotlin.reflect.KProperty
class OptionDescriptor<T>
interface ArgumentValueDelegate<T> {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = listOf("OK") as T
}
abstract class CLIEntity<TResult> constructor(val delegate: ArgumentValueDelegate<TResult>) {
operator fun provideDelegate(thisRef: Any?, prop: KProperty<*>): ArgumentValueDelegate<TResult> = delegate
}
abstract class AbstractSingleOption<T : Any, TResult> constructor(delegate: ArgumentValueDelegate<TResult>) : CLIEntity<TResult>(delegate)
class ArgumentSingleNullableValue<T : Any>(descriptor: OptionDescriptor<T>): ArgumentValueDelegate<T?>
class SingleNullableOption<T : Any> constructor(descriptor: OptionDescriptor<T>) : AbstractSingleOption<T, T?>(ArgumentSingleNullableValue(descriptor))
fun box(): String {
val x: List<Any>? by SingleNullableOption(OptionDescriptor())
return x?.get(0).toString()
}