Files
kotlin-fork/compiler/testData/codegen/box/delegatedProperty/provideDelegate/genericProvideDelegateOnNumberLiteral.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

29 lines
719 B
Kotlin
Vendored

// WITH_STDLIB
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
operator fun <C, T> T.provideDelegate(thisRef: C, property: KProperty<*>) =
object : ReadOnlyProperty<C, T> {
override operator fun getValue(thisRef: C, property: KProperty<*>) = this@provideDelegate
}
val byInt by 42
val byIntAsLong: Long by 42L
val byIntNullable: Int? by 42
val byString by "str"
val byStringNullable: String? = "strNullable"
fun box(): String {
if (byInt != 42) return "fail1"
if (byIntAsLong != 42L) return "fail2"
if (byIntNullable != 42) return "fail3"
if (byString != "str") return "fail4"
if (byStringNullable != "strNullable") return "fail5"
return "OK"
}