Files
kotlin-fork/compiler/testData/codegen/box/delegatedProperty/provideDelegate/genericProvideDelegateOnNumberLiteral.kt
T
Mikhail Zarechenskiy fcf7a55ccc Fix delegated property resolve on number literals and proper types
There is no need to update type of delegate expression if it's already
 resolved correctly (doesn't include non-proper types). In almost all
 cases it was fine except number literals as there we didn't box
 expression in backend and got problems at bytecode verification stage

 #KT-40057 Fixed
2020-07-17 14:27:20 +03:00

29 lines
747 B
Kotlin
Vendored

// !LANGUAGE: +NewInference
// WITH_RUNTIME
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"
}