Update compiler tests to use KProperty instead of PropertyMetadata

This commit is contained in:
Alexander Udalov
2015-10-13 14:02:29 +03:00
parent a6846b3967
commit 51bf68ce27
68 changed files with 265 additions and 139 deletions
@@ -1,6 +1,6 @@
== Delegate == == Delegate ==
class Delegate { class Delegate {
fun getValue(_this: Nothing?, p: PropertyMetadata): Int = 0 fun getValue(_this: Nothing?, p: KProperty<*>): Int = 0
} }
--------------------- ---------------------
L0: L0:
@@ -13,24 +13,24 @@ sink:
<SINK> PREV:[<ERROR>, <END>] <SINK> PREV:[<ERROR>, <END>]
===================== =====================
== getValue == == getValue ==
fun getValue(_this: Nothing?, p: PropertyMetadata): Int = 0 fun getValue(_this: Nothing?, p: KProperty<*>): Int = 0
--------------------- ---------------------
L0: L0:
1 <START> 1 <START>
v(_this: Nothing?) v(_this: Nothing?)
magic[FAKE_INITIALIZER](_this: Nothing?) -> <v0> magic[FAKE_INITIALIZER](_this: Nothing?) -> <v0>
w(_this|<v0>) w(_this|<v0>)
v(p: PropertyMetadata) v(p: KProperty<*>)
magic[FAKE_INITIALIZER](p: PropertyMetadata) -> <v1> magic[FAKE_INITIALIZER](p: KProperty<*>) -> <v1>
w(p|<v1>) w(p|<v1>)
r(0) -> <v2> r(0) -> <v2>
ret(*|<v2>) L1 ret(*|<v2>) L1
L1: L1:
<END> NEXT:[<SINK>] <END> NEXT:[<SINK>]
error: error:
<ERROR> PREV:[] <ERROR> PREV:[]
sink: sink:
<SINK> PREV:[<ERROR>, <END>] <SINK> PREV:[<ERROR>, <END>]
===================== =====================
== a == == a ==
val a = Delegate() val a = Delegate()
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(_this: Nothing?, p: PropertyMetadata): Int = 0 fun getValue(_this: Nothing?, p: KProperty<*>): Int = 0
} }
val a = Delegate() val a = Delegate()
@@ -1,15 +1,15 @@
== Delegate == == Delegate ==
class Delegate { class Delegate {
fun getValue(_this: Nothing?, p: PropertyMetadata): Int = 0 fun getValue(_this: Nothing?, p: KProperty<*>): Int = 0
} }
--------------------- ---------------------
===================== =====================
== getValue == == getValue ==
fun getValue(_this: Nothing?, p: PropertyMetadata): Int = 0 fun getValue(_this: Nothing?, p: KProperty<*>): Int = 0
--------------------- ---------------------
<v0>: {<: Nothing?} NEW: magic[FAKE_INITIALIZER](_this: Nothing?) -> <v0> <v0>: {<: Nothing?} NEW: magic[FAKE_INITIALIZER](_this: Nothing?) -> <v0>
<v1>: {<: PropertyMetadata} NEW: magic[FAKE_INITIALIZER](p: PropertyMetadata) -> <v1> <v1>: {<: KProperty<*>} NEW: magic[FAKE_INITIALIZER](p: KProperty<*>) -> <v1>
0 <v2>: Int NEW: r(0) -> <v2> 0 <v2>: Int NEW: r(0) -> <v2>
===================== =====================
== a == == a ==
val a = Delegate() val a = Delegate()
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
// KT-5612 // KT-5612
class Delegate { class Delegate {
public fun getValue(thisRef: Any?, prop: PropertyMetadata): String { public fun getValue(thisRef: Any?, prop: KProperty<*>): String {
return "OK" return "OK"
} }
} }
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
} }
class B { class B {
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1 fun getValue(t: Any?, p: KProperty<*>): Int = 1
} }
class AImpl { class AImpl {
@@ -1,10 +1,12 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = Derived() var inner = Derived()
fun getValue(t: Any?, p: PropertyMetadata): Derived { fun getValue(t: Any?, p: KProperty<*>): Derived {
inner = Derived(inner.a + "-get") inner = Derived(inner.a + "-get")
return inner return inner
} }
fun setValue(t: Any?, p: PropertyMetadata, i: Base) { inner = Derived(inner.a + "-" + i.a + "-set") } fun setValue(t: Any?, p: KProperty<*>, i: Base) { inner = Derived(inner.a + "-" + i.a + "-set") }
} }
class A { class A {
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: Any?, p: PropertyMetadata, s: String = ""): Int = 1 fun getValue(t: Any?, p: KProperty<*>, s: String = ""): Int = 1
} }
val prop: Int by Delegate() val prop: Int by Delegate()
@@ -1,10 +1,12 @@
import kotlin.reflect.KProperty
class A { class A {
var prop: Int by Delegate() var prop: Int by Delegate()
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
} }
} }
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
} }
class A { class A {
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
} }
fun foo() = Delegate() fun foo() = Delegate()
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
} }
val p = Delegate() val p = Delegate()
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: A, p: PropertyMetadata): Int = 1 fun getValue(t: A, p: KProperty<*>): Int = 1
} }
val A.prop: Int by Delegate() val A.prop: Int by Delegate()
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: F.A, p: PropertyMetadata): Int = 1 fun getValue(t: F.A, p: KProperty<*>): Int = 1
} }
class F { class F {
@@ -1,6 +1,8 @@
import kotlin.reflect.KProperty
class Delegate<T>(var inner: T) { class Delegate<T>(var inner: T) {
fun getValue(t: Any?, p: PropertyMetadata): T = inner fun getValue(t: Any?, p: KProperty<*>): T = inner
fun setValue(t: Any?, p: PropertyMetadata, i: T) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
} }
class A { class A {
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
} }
fun Delegate.getValue(t: Any?, p: PropertyMetadata): Int = 1 fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
class A { class A {
val prop: Int by Delegate() val prop: Int by Delegate()
@@ -1,8 +1,10 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
} }
class A { class A {
fun Delegate.getValue(t: Any?, p: PropertyMetadata): Int = 1 fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
val prop: Int by Delegate() val prop: Int by Delegate()
} }
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1 fun getValue(t: Any?, p: KProperty<*>): Int = 1
} }
class A { class A {
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
} }
class A { class A {
@@ -15,4 +17,3 @@ fun box(): String {
if (c.prop != 2) return "fail set" if (c.prop != 2) return "fail set"
return "OK" return "OK"
} }
+3 -1
View File
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1 fun getValue(t: Any?, p: KProperty<*>): Int = 1
} }
interface A { interface A {
@@ -1,6 +1,8 @@
import kotlin.reflect.KProperty
class Delegate<T>(var inner: T) { class Delegate<T>(var inner: T) {
fun getValue(t: Any?, p: PropertyMetadata): T = inner fun getValue(t: Any?, p: KProperty<*>): T = inner
fun setValue(t: Any?, p: PropertyMetadata, i: T) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
} }
class A { class A {
+4 -2
View File
@@ -1,6 +1,8 @@
import kotlin.reflect.KProperty
class Delegate<T>(var inner: T) { class Delegate<T>(var inner: T) {
fun getValue(t: Any?, p: PropertyMetadata): T = inner fun getValue(t: Any?, p: KProperty<*>): T = inner
fun setValue(t: Any?, p: PropertyMetadata, i: T) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
} }
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
} }
class A { class A {
@@ -1,4 +1,5 @@
import java.util.IdentityHashMap import java.util.IdentityHashMap
import kotlin.reflect.KProperty
class A { class A {
var foo: Int by IntHandler var foo: Int by IntHandler
@@ -12,23 +13,23 @@ val baz: String by StringHandler
val metadatas = IdentityHashMap<PropertyMetadata, Unit>() val metadatas = IdentityHashMap<KProperty<*>, Unit>()
fun record(p: PropertyMetadata) = metadatas.put(p, Unit) fun record(p: KProperty<*>) = metadatas.put(p, Unit)
object IntHandler { object IntHandler {
fun getValue(t: Any?, p: PropertyMetadata): Int { record(p); return 42 } fun getValue(t: Any?, p: KProperty<*>): Int { record(p); return 42 }
fun setValue(t: Any?, p: PropertyMetadata, value: Int) { record(p) } fun setValue(t: Any?, p: KProperty<*>, value: Int) { record(p) }
} }
object AnyHandler { object AnyHandler {
fun getValue(t: Any?, p: PropertyMetadata): Any? { record(p); return 3.14 } fun getValue(t: Any?, p: KProperty<*>): Any? { record(p); return 3.14 }
fun setValue(t: Any?, p: PropertyMetadata, value: Any?) { record(p) } fun setValue(t: Any?, p: KProperty<*>, value: Any?) { record(p) }
} }
object StringHandler { object StringHandler {
fun getValue(t: Any?, p: PropertyMetadata): String { record(p); return p.name } fun getValue(t: Any?, p: KProperty<*>): String { record(p); return p.name }
fun setValue(t: Any?, p: PropertyMetadata, value: String) { record(p) } fun setValue(t: Any?, p: KProperty<*>, value: String) { record(p) }
} }
fun box(): String { fun box(): String {
@@ -40,7 +41,7 @@ fun box(): String {
baz + A.bar baz + A.bar
if (metadatas.keys.size != 3) if (metadatas.keys.size != 3)
return "Fail: only three instances of PropertyMetadata should have been created\n${metadatas.keys}" return "Fail: only three instances of KProperty should have been created\n${metadatas.keySet()}"
return "OK" return "OK"
} }
@@ -1,9 +1,11 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
} }
fun Delegate.setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun Delegate.setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
class A { class A {
var prop: Int by Delegate() var prop: Int by Delegate()
@@ -1,10 +1,12 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
} }
class A { class A {
fun Delegate.setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun Delegate.setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
var prop: Int by Delegate() var prop: Int by Delegate()
} }
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1 fun getValue(t: Any?, p: KProperty<*>): Int = 1
} }
val prop: Int by Delegate() val prop: Int by Delegate()
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
} }
var prop: Int by Delegate() var prop: Int by Delegate()
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate<T>(val f: (T) -> Int) { class Delegate<T>(val f: (T) -> Int) {
fun getValue(t: T, p: PropertyMetadata): Int = f(t) fun getValue(t: T, p: KProperty<*>): Int = f(t)
} }
val p = Delegate<A> { t -> t.foo() } val p = Delegate<A> { t -> t.foo() }
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1 fun getValue(t: Any?, p: KProperty<*>): Int = 1
} }
class A { class A {
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i } fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
} }
class A { class A {
+3 -1
View File
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: Any?, vararg p: PropertyMetadata): Int = 1 fun getValue(t: Any?, vararg p: KProperty<*>): Int = 1
} }
val prop: Int by Delegate() val prop: Int by Delegate()
+4 -2
View File
@@ -1,14 +1,16 @@
import kotlin.reflect.KProperty
public open class TestDelegate<T: Any>(private val initializer: () -> T) { public open class TestDelegate<T: Any>(private val initializer: () -> T) {
private var value: T? = null private var value: T? = null
public open fun getValue(thisRef: Any?, desc: PropertyMetadata): T { public open fun getValue(thisRef: Any?, desc: KProperty<*>): T {
if (value == null) { if (value == null) {
value = initializer() value = initializer()
} }
return value!! return value!!
} }
public open fun setValue(thisRef: Any?, desc: PropertyMetadata, svalue : T) { public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : T) {
value = svalue value = svalue
} }
} }
+3 -1
View File
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class D { class D {
fun getValue(a: Any, p: PropertyMetadata) { } fun getValue(a: Any, p: KProperty<*>) { }
} }
object P { object P {
@@ -1,6 +1,8 @@
import kotlin.reflect.KProperty
class Holder(var value: Int) { class Holder(var value: Int) {
fun getValue(that: Any?, desc: PropertyMetadata) = value fun getValue(that: Any?, desc: KProperty<*>) = value
fun setValue(that: Any?, desc: PropertyMetadata, newValue: Int) { value = newValue } fun setValue(that: Any?, desc: KProperty<*>, newValue: Int) { value = newValue }
} }
interface R<T: Comparable<T>> { interface R<T: Comparable<T>> {
+5 -3
View File
@@ -1,8 +1,10 @@
// java.lang.VerifyError: (class: NotImplemented, method: get signature: (Ljava/lang/Object;Ljet/PropertyMetadata;)Ljava/lang/Object;) Unable to pop operand off an empty stack import kotlin.reflect.KProperty
// java.lang.VerifyError: (class: NotImplemented, method: get signature: (Ljava/lang/Object;Lkotlin/reflect/KProperty;)Ljava/lang/Object;) Unable to pop operand off an empty stack
class NotImplemented<T>(){ class NotImplemented<T>(){
fun getValue(thisRef: Any?, prop: PropertyMetadata): T = notImplemented() fun getValue(thisRef: Any?, prop: KProperty<*>): T = notImplemented()
fun setValue(thisRef: Any?, prop: PropertyMetadata, value: T) = notImplemented() fun setValue(thisRef: Any?, prop: KProperty<*>, value: T) = notImplemented()
} }
fun notImplemented() : Nothing = notImplemented() fun notImplemented() : Nothing = notImplemented()
+4 -2
View File
@@ -1,12 +1,14 @@
import kotlin.reflect.KProperty
// java.lang.ClassNotFoundException: kotlin.Nothing // java.lang.ClassNotFoundException: kotlin.Nothing
var currentAccountId: Int? by SessionAccessor() var currentAccountId: Int? by SessionAccessor()
class SessionAccessor<T> { class SessionAccessor<T> {
fun getValue(o : Nothing?, desc: PropertyMetadata): T { fun getValue(o : Nothing?, desc: KProperty<*>): T {
return null as T return null as T
} }
fun setValue(o : Nothing?, desc: PropertyMetadata, value: T) { fun setValue(o : Nothing?, desc: KProperty<*>, value: T) {
} }
} }
@@ -1,3 +1,5 @@
import kotlin.reflect.KProperty
@Retention(AnnotationRetention.RUNTIME) @Retention(AnnotationRetention.RUNTIME)
annotation class First annotation class First
@@ -7,11 +9,11 @@ class MyClass() {
} }
class Delegate { class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): String { fun getValue(t: Any?, p: KProperty<*>): String {
return "OK" return "OK"
} }
fun setValue(t: Any?, p: PropertyMetadata, i: String) {} fun setValue(t: Any?, p: KProperty<*>, i: String) {}
} }
fun box(): String { fun box(): String {
@@ -1,3 +1,5 @@
import kotlin.reflect.KProperty
val four: Int by NumberDecrypter val four: Int by NumberDecrypter
class A { class A {
@@ -5,7 +7,7 @@ class A {
} }
object NumberDecrypter { object NumberDecrypter {
fun getValue(instance: Any?, data: PropertyMetadata) = when (data.name) { fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
"four" -> 4 "four" -> 4
"two" -> 2 "two" -> 2
else -> throw AssertionError() else -> throw AssertionError()
@@ -1,13 +1,15 @@
import kotlin.reflect.KProperty
var result: String by Delegate var result: String by Delegate
object Delegate { object Delegate {
var value = "lol" var value = "lol"
fun getValue(instance: Any?, data: PropertyMetadata): String { fun getValue(instance: Any?, data: KProperty<*>): String {
return value return value
} }
fun setValue(instance: Any?, data: PropertyMetadata, newValue: String) { fun setValue(instance: Any?, data: KProperty<*>, newValue: String) {
value = newValue value = newValue
} }
} }
@@ -1,6 +1,7 @@
//For KT-6020 //For KT-6020
import kotlin.reflect.KProperty1 import kotlin.reflect.KProperty1
import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KProperty
class Value<T>(var value: T = null as T, var text: String? = null) class Value<T>(var value: T = null as T, var text: String? = null)
@@ -9,7 +10,7 @@ val <T> Value<T>.additionalText by DVal(Value<T>::text) //works
val <T> Value<T>.additionalValue by DVal(Value<T>::value) //not work val <T> Value<T>.additionalValue by DVal(Value<T>::value) //not work
class DVal<T, R, P: KProperty1<T, R>>(val kmember: P) { class DVal<T, R, P: KProperty1<T, R>>(val kmember: P) {
fun getValue(t: T, p: PropertyMetadata): R { fun getValue(t: T, p: KProperty<*>): R {
return kmember.get(t) return kmember.get(t)
} }
} }
@@ -1,4 +1,5 @@
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.reflect.KProperty
class Project { class Project {
fun <T> getInstance(cls: Class<T>): T = fun <T> getInstance(cls: Class<T>): T =
@@ -9,7 +10,7 @@ class Project {
} }
} }
inline fun <reified T : Any> Project.getValue(t: Any?, p: PropertyMetadata): T = getInstance(javaClass<T>()) inline fun <reified T : Any> Project.getValue(t: Any?, p: KProperty<*>): T = getInstance(javaClass<T>())
val project = Project() val project = Project()
val x1: Int by project val x1: Int by project
@@ -1,3 +1,5 @@
import kotlin.reflect.KProperty
class C { class C {
// All these properties should have corresponding accessors // All these properties should have corresponding accessors
private val valWithGet: String private val valWithGet: String
@@ -25,7 +27,7 @@ class C {
object Delegate { object Delegate {
fun getValue(x: C, p: PropertyMetadata) = throw AssertionError() fun getValue(x: C, p: KProperty<*>) = throw AssertionError()
fun setValue(x: C, p: PropertyMetadata, value: Int) = throw AssertionError() fun setValue(x: C, p: KProperty<*>, value: Int) = throw AssertionError()
} }
@@ -1,9 +1,11 @@
package test package test
import kotlin.reflect.KProperty
annotation class Anno annotation class Anno
class Class { class Class {
@Anno val x: Int by object { @Anno val x: Int by object {
fun getValue(thiz: Class, data: PropertyMetadata) = null!! fun getValue(thiz: Class, data: KProperty<*>) = null!!
} }
} }
@@ -1,7 +1,9 @@
package test package test
import kotlin.reflect.KProperty
annotation class Anno annotation class Anno
@Anno val x: Int by object { @Anno val x: Int by object {
fun getValue(thiz: Any?, data: PropertyMetadata) = null!! fun getValue(thiz: Any?, data: KProperty<*>) = null!!
} }
@@ -1,11 +1,13 @@
//ALLOW_AST_ACCESS //ALLOW_AST_ACCESS
package test package test
import kotlin.reflect.KProperty
class A { class A {
var a by MyProperty() var a by MyProperty()
} }
class MyProperty<T> { class MyProperty<T> {
fun getValue(t: T, p: PropertyMetadata): Int = 42 fun getValue(t: T, p: KProperty<*>): Int = 42
fun setValue(t: T, p: PropertyMetadata, i: Int) {} fun setValue(t: T, p: KProperty<*>, i: Int) {}
} }
@@ -9,6 +9,6 @@ public final class A {
public final class MyProperty</*0*/ T> { public final class MyProperty</*0*/ T> {
/*primary*/ public constructor MyProperty</*0*/ T>() /*primary*/ public constructor MyProperty</*0*/ T>()
public final fun getValue(/*0*/ t: T, /*1*/ p: kotlin.PropertyMetadata): kotlin.Int public final fun getValue(/*0*/ t: T, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Int
public final fun setValue(/*0*/ t: T, /*1*/ p: kotlin.PropertyMetadata, /*2*/ i: kotlin.Int): kotlin.Unit public final fun setValue(/*0*/ t: T, /*1*/ p: kotlin.reflect.KProperty<*>, /*2*/ i: kotlin.Int): kotlin.Unit
} }
@@ -1,14 +1,16 @@
import kotlin.reflect.KProperty
class MyClass() { class MyClass() {
public var x: Int by Delegate() public var x: Int by Delegate()
private set private set
} }
class Delegate { class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int { fun getValue(t: Any?, p: KProperty<*>): Int {
return 1 return 1
} }
fun setValue(t: Any?, p: PropertyMetadata, i: Int) {} fun setValue(t: Any?, p: KProperty<*>, i: Int) {}
} }
// TESTED_OBJECT_KIND: function // TESTED_OBJECT_KIND: function
@@ -1,9 +1,11 @@
import kotlin.reflect.KProperty
class TestDelegate() { class TestDelegate() {
fun getValue(thisRef: Any?, desc: PropertyMetadata): Int { fun getValue(thisRef: Any?, desc: KProperty<*>): Int {
return 10 return 10
} }
public open fun setValue(thisRef: Any?, desc: PropertyMetadata, svalue : Int) { public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : Int) {
} }
} }
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class TestDelegate() { class TestDelegate() {
fun getValue(thisRef: Any?, desc: PropertyMetadata): Int { fun getValue(thisRef: Any?, desc: KProperty<*>): Int {
return 10 return 10
} }
} }
@@ -1,14 +1,16 @@
import kotlin.reflect.KProperty
public open class TestDelegate<T: Any>(private val initializer: () -> T) { public open class TestDelegate<T: Any>(private val initializer: () -> T) {
private var value: T? = null private var value: T? = null
public open fun getValue(thisRef: Any?, desc: PropertyMetadata): T { public open fun getValue(thisRef: Any?, desc: KProperty<*>): T {
if (value == null) { if (value == null) {
value = initializer() value = initializer()
} }
return value!! return value!!
} }
public open fun setValue(thisRef: Any?, desc: PropertyMetadata, svalue : T) { public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : T) {
value = svalue value = svalue
} }
} }
@@ -1,14 +1,16 @@
import kotlin.reflect.KProperty
public open class TestDelegate<T: Any>(private val initializer: () -> T) { public open class TestDelegate<T: Any>(private val initializer: () -> T) {
private var value: T? = null private var value: T? = null
public open fun getValue(thisRef: Any?, desc: PropertyMetadata): T { public open fun getValue(thisRef: Any?, desc: KProperty<*>): T {
if (value == null) { if (value == null) {
value = initializer() value = initializer()
} }
return value!! return value!!
} }
public open fun setValue(thisRef: Any?, desc: PropertyMetadata, svalue : T) { public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : T) {
value = svalue value = svalue
} }
} }
@@ -1,9 +1,11 @@
import kotlin.reflect.KProperty
class TestDelegate() { class TestDelegate() {
fun getValue(thisRef: Any?, desc: PropertyMetadata): Int { fun getValue(thisRef: Any?, desc: KProperty<*>): Int {
return 10 return 10
} }
public open fun setValue(thisRef: Any?, desc: PropertyMetadata, svalue : Int) { public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : Int) {
} }
} }
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class TestDelegate() { class TestDelegate() {
fun getValue(thisRef: Any?, desc: PropertyMetadata): Int { fun getValue(thisRef: Any?, desc: KProperty<*>): Int {
return 10 return 10
} }
} }
@@ -1,8 +1,10 @@
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/. // This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
package foo package foo
import kotlin.reflect.KProperty
object NumberDecrypter { object NumberDecrypter {
fun getValue(instance: Any?, data: PropertyMetadata) = when (data.name) { fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
"four" -> 4 "four" -> 4
"two" -> 2 "two" -> 2
else -> throw Exception() else -> throw Exception()
@@ -1,14 +1,16 @@
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/. // This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
package foo package foo
import kotlin.reflect.KProperty
object Delegate { object Delegate {
var value = "lol" var value = "lol"
fun getValue(instance: Any?, data: PropertyMetadata): String { fun getValue(instance: Any?, data: KProperty<*>): String {
return value return value
} }
fun setValue(instance: Any?, data: PropertyMetadata, newValue: String) { fun setValue(instance: Any?, data: KProperty<*>, newValue: String) {
value = newValue value = newValue
} }
} }
@@ -1,5 +1,7 @@
package foo package foo
import kotlin.reflect.KProperty
class State(var realValue: Int) class State(var realValue: Int)
fun format(event: String, property: String, value: Int): String fun format(event: String, property: String, value: Int): String
@@ -8,12 +10,12 @@ fun format(event: String, property: String, value: Int): String
object LoggerDelegate { object LoggerDelegate {
var log = "" var log = ""
fun getValue(state: State, desc: PropertyMetadata): Int { fun getValue(state: State, desc: KProperty<*>): Int {
log += format("get", desc.name, state.realValue) log += format("get", desc.name, state.realValue)
return state.realValue return state.realValue
} }
fun setValue(state: State, desc: PropertyMetadata, value: Int) { fun setValue(state: State, desc: KProperty<*>, value: Int) {
log += format("set", desc.name, value) log += format("set", desc.name, value)
state.realValue = value state.realValue = value
} }
@@ -1,9 +1,11 @@
package foo package foo
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { fun setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i inner = i
} }
} }
@@ -1,9 +1,11 @@
package foo package foo
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { fun setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i inner = i
} }
} }
@@ -1,9 +1,11 @@
package foo package foo
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { fun setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i inner = i
} }
} }
@@ -1,9 +1,11 @@
package foo package foo
import kotlin.reflect.KProperty
class Delegate { class Delegate {
} }
fun Delegate.getValue(t: Any?, p: PropertyMetadata): Int = 1 fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
class A { class A {
val prop: Int by Delegate() val prop: Int by Delegate()
@@ -1,14 +1,16 @@
package foo package foo
import kotlin.reflect.KProperty
interface WithName { interface WithName {
var name: String var name: String
} }
class GetPropertyName() { class GetPropertyName() {
fun getValue(withName: WithName, property: PropertyMetadata): String { fun getValue(withName: WithName, property: KProperty<*>): String {
return withName.name + ":" + property.name; return withName.name + ":" + property.name;
} }
fun setValue(withName: WithName, property: PropertyMetadata, value: String) { fun setValue(withName: WithName, property: KProperty<*>, value: String) {
withName.name = value + ":" + property.name withName.name = value + ":" + property.name
} }
} }
@@ -1,11 +1,13 @@
package foo package foo
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
} }
fun Delegate.setValue(t: Any?, p: PropertyMetadata, i: Int) { fun Delegate.setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i inner = i
} }
+4 -2
View File
@@ -1,14 +1,16 @@
package foo package foo
import kotlin.reflect.KProperty
interface WithNumber { interface WithNumber {
var number: Int var number: Int
} }
class IncNumber(val inc: Int) { class IncNumber(val inc: Int) {
fun getValue(withNumber: WithNumber, property: PropertyMetadata): Int { fun getValue(withNumber: WithNumber, property: KProperty<*>): Int {
return withNumber.number + inc; return withNumber.number + inc;
} }
fun setValue(withNumber: WithNumber, property: PropertyMetadata, value: Int) { fun setValue(withNumber: WithNumber, property: KProperty<*>, value: Int) {
withNumber.number = value; withNumber.number = value;
} }
} }
@@ -1,7 +1,9 @@
package foo package foo
import kotlin.reflect.KProperty
class Delegate { class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1 fun getValue(t: Any?, p: KProperty<*>): Int = 1
} }
val prop: Int by Delegate() val prop: Int by Delegate()
@@ -1,9 +1,11 @@
package foo package foo
import kotlin.reflect.KProperty
class Delegate { class Delegate {
var inner = 1 var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { fun setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i inner = i
} }
} }
@@ -1,18 +1,20 @@
package foo package foo
import kotlin.reflect.KProperty
interface Getter<T> { interface Getter<T> {
fun get(): T fun get(): T
} }
class Delegate<T>(val getter: Getter<T>) { class Delegate<T>(val getter: Getter<T>) {
var t: T? = null var t: T? = null
fun getValue(obj: Any, property: PropertyMetadata): T { fun getValue(obj: Any, property: KProperty<*>): T {
if (t != null) { if (t != null) {
return t!! return t!!
} }
return getter.get() return getter.get()
} }
fun setValue(obj: Any, property: PropertyMetadata, value: T) { fun setValue(obj: Any, property: KProperty<*>, value: T) {
t = value t = value
} }
} }
@@ -1,5 +1,7 @@
package foo package foo
import kotlin.reflect.KProperty
class State(var value: Int) class State(var value: Int)
interface Base { interface Base {
@@ -7,9 +9,9 @@ interface Base {
} }
class Delegate(val multiplier: Int) { class Delegate(val multiplier: Int) {
fun getValue(state: State, desc: PropertyMetadata): Int = multiplier * state.value fun getValue(state: State, desc: KProperty<*>): Int = multiplier * state.value
fun setValue(state: State, desc: PropertyMetadata, value: Int) { fun setValue(state: State, desc: KProperty<*>, value: Int) {
state.value = value / multiplier state.value = value / multiplier
} }