Files
kotlin-fork/compiler/testData/codegen/box/reified/DIExample.kt
T
Juan Chen 4f6fe1d0ca [FIR]: fix translation of top-level property accesses like array.indices
This commit addresses the following issues:

* accessors didn't take into account their property's receiver type,
which caused NoSuchMethod due to signature mismatch. Now the property's
receiver type is passed to Fir2Ir translation of accessors.

* property's parent was not class, e.g., kotlin.collections.indices.
Now the symbol table collects WrappedPropertyDescriptorWithContainerSource
besides WrappedFunctionDescriptorWithContainerSource, so that
facade classes for such properties can be generated before codegen.

* accessor's parent was not class. Now the containerSource of
the property descriptor is passed to accessor descriptor.
2020-02-25 12:13:42 +03:00

29 lines
601 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_RUNTIME
import kotlin.test.assertEquals
import kotlin.reflect.KProperty
class Project {
fun <T> getInstance(cls: Class<T>): T =
when (cls.getName()) {
"java.lang.Integer" -> 1 as T
"java.lang.String" -> "OK" as T
else -> null!!
}
}
inline operator fun <reified T : Any> Project.getValue(t: Any?, p: KProperty<*>): T = getInstance(T::class.java)
val project = Project()
val x1: Int by project
val x2: String by project
fun box(): String {
assertEquals(1, x1)
assertEquals("OK", x2)
return "OK"
}