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 ==
class Delegate {
fun getValue(_this: Nothing?, p: PropertyMetadata): Int = 0
fun getValue(_this: Nothing?, p: KProperty<*>): Int = 0
}
---------------------
L0:
@@ -13,24 +13,24 @@ sink:
<SINK> PREV:[<ERROR>, <END>]
=====================
== getValue ==
fun getValue(_this: Nothing?, p: PropertyMetadata): Int = 0
fun getValue(_this: Nothing?, p: KProperty<*>): Int = 0
---------------------
L0:
1 <START>
v(_this: Nothing?)
magic[FAKE_INITIALIZER](_this: Nothing?) -> <v0>
w(_this|<v0>)
v(p: PropertyMetadata)
magic[FAKE_INITIALIZER](p: PropertyMetadata) -> <v1>
v(p: KProperty<*>)
magic[FAKE_INITIALIZER](p: KProperty<*>) -> <v1>
w(p|<v1>)
r(0) -> <v2>
ret(*|<v2>) L1
L1:
<END> NEXT:[<SINK>]
<END> NEXT:[<SINK>]
error:
<ERROR> PREV:[]
<ERROR> PREV:[]
sink:
<SINK> PREV:[<ERROR>, <END>]
<SINK> PREV:[<ERROR>, <END>]
=====================
== a ==
val a = Delegate()
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
fun getValue(_this: Nothing?, p: PropertyMetadata): Int = 0
fun getValue(_this: Nothing?, p: KProperty<*>): Int = 0
}
val a = Delegate()
val b by a
val b by a
@@ -1,15 +1,15 @@
== Delegate ==
class Delegate {
fun getValue(_this: Nothing?, p: PropertyMetadata): Int = 0
fun getValue(_this: Nothing?, p: KProperty<*>): Int = 0
}
---------------------
=====================
== 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>
<v1>: {<: PropertyMetadata} NEW: magic[FAKE_INITIALIZER](p: PropertyMetadata) -> <v1>
0 <v2>: Int NEW: r(0) -> <v2>
<v0>: {<: Nothing?} NEW: magic[FAKE_INITIALIZER](_this: Nothing?) -> <v0>
<v1>: {<: KProperty<*>} NEW: magic[FAKE_INITIALIZER](p: KProperty<*>) -> <v1>
0 <v2>: Int NEW: r(0) -> <v2>
=====================
== a ==
val a = Delegate()
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
// KT-5612
class Delegate {
public fun getValue(thisRef: Any?, prop: PropertyMetadata): String {
public fun getValue(thisRef: Any?, prop: KProperty<*>): String {
return "OK"
}
}
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
}
class B {
@@ -18,4 +20,4 @@ class B {
fun box(): String {
B().test()
return "OK"
}
}
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1
fun getValue(t: Any?, p: KProperty<*>): Int = 1
}
class AImpl {
@@ -1,10 +1,12 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = Derived()
fun getValue(t: Any?, p: PropertyMetadata): Derived {
fun getValue(t: Any?, p: KProperty<*>): Derived {
inner = Derived(inner.a + "-get")
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 {
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
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()
@@ -1,10 +1,12 @@
import kotlin.reflect.KProperty
class A {
var prop: Int by Delegate()
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
}
}
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
}
class A {
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
}
fun foo() = Delegate()
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
}
val p = Delegate()
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate {
fun getValue(t: A, p: PropertyMetadata): Int = 1
fun getValue(t: A, p: KProperty<*>): Int = 1
}
val A.prop: Int by Delegate()
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate {
fun getValue(t: F.A, p: PropertyMetadata): Int = 1
fun getValue(t: F.A, p: KProperty<*>): Int = 1
}
class F {
@@ -15,4 +17,4 @@ class F {
fun box(): String {
return if(F().foo() == 1) "OK" else "fail"
}
}
@@ -1,6 +1,8 @@
import kotlin.reflect.KProperty
class Delegate<T>(var inner: T) {
fun getValue(t: Any?, p: PropertyMetadata): T = inner
fun setValue(t: Any?, p: PropertyMetadata, i: T) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): T = inner
fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
}
class A {
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
}
fun Delegate.getValue(t: Any?, p: PropertyMetadata): Int = 1
fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
class A {
val prop: Int by Delegate()
@@ -1,8 +1,10 @@
import kotlin.reflect.KProperty
class Delegate {
}
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()
}
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1
fun getValue(t: Any?, p: KProperty<*>): Int = 1
}
class A {
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
}
class A {
@@ -15,4 +17,3 @@ fun box(): String {
if (c.prop != 2) return "fail set"
return "OK"
}
+3 -1
View File
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1
fun getValue(t: Any?, p: KProperty<*>): Int = 1
}
interface A {
@@ -1,6 +1,8 @@
import kotlin.reflect.KProperty
class Delegate<T>(var inner: T) {
fun getValue(t: Any?, p: PropertyMetadata): T = inner
fun setValue(t: Any?, p: PropertyMetadata, i: T) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): T = inner
fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
}
class A {
+5 -3
View File
@@ -1,6 +1,8 @@
import kotlin.reflect.KProperty
class Delegate<T>(var inner: T) {
fun getValue(t: Any?, p: PropertyMetadata): T = inner
fun setValue(t: Any?, p: PropertyMetadata, i: T) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): T = inner
fun setValue(t: Any?, p: KProperty<*>, i: T) { inner = i }
}
@@ -32,4 +34,4 @@ fun box() : String {
if (FooTrait.B.f != 12) return "fail 6"
return "OK"
}
}
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
}
class A {
@@ -17,4 +19,4 @@ class A {
fun box(): String {
return A().test()
}
}
@@ -1,4 +1,5 @@
import java.util.IdentityHashMap
import kotlin.reflect.KProperty
class A {
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 {
fun getValue(t: Any?, p: PropertyMetadata): Int { record(p); return 42 }
fun setValue(t: Any?, p: PropertyMetadata, value: Int) { record(p) }
fun getValue(t: Any?, p: KProperty<*>): Int { record(p); return 42 }
fun setValue(t: Any?, p: KProperty<*>, value: Int) { record(p) }
}
object AnyHandler {
fun getValue(t: Any?, p: PropertyMetadata): Any? { record(p); return 3.14 }
fun setValue(t: Any?, p: PropertyMetadata, value: Any?) { record(p) }
fun getValue(t: Any?, p: KProperty<*>): Any? { record(p); return 3.14 }
fun setValue(t: Any?, p: KProperty<*>, value: Any?) { record(p) }
}
object StringHandler {
fun getValue(t: Any?, p: PropertyMetadata): String { record(p); return p.name }
fun setValue(t: Any?, p: PropertyMetadata, value: String) { record(p) }
fun getValue(t: Any?, p: KProperty<*>): String { record(p); return p.name }
fun setValue(t: Any?, p: KProperty<*>, value: String) { record(p) }
}
fun box(): String {
@@ -40,7 +41,7 @@ fun box(): String {
baz + A.bar
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"
}
@@ -1,9 +1,11 @@
import kotlin.reflect.KProperty
class Delegate {
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 {
var prop: Int by Delegate()
@@ -1,10 +1,12 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun getValue(t: Any?, p: KProperty<*>): Int = inner
}
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()
}
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1
fun getValue(t: Any?, p: KProperty<*>): Int = 1
}
val prop: Int by Delegate()
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
}
var prop: Int by Delegate()
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
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() }
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1
fun getValue(t: Any?, p: KProperty<*>): Int = 1
}
class A {
@@ -1,7 +1,9 @@
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) { inner = i }
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) { inner = i }
}
class A {
+3 -1
View File
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
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()
+4 -2
View File
@@ -1,14 +1,16 @@
import kotlin.reflect.KProperty
public open class TestDelegate<T: Any>(private val initializer: () -> T) {
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) {
value = initializer()
}
return value!!
}
public open fun setValue(thisRef: Any?, desc: PropertyMetadata, svalue : T) {
public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : T) {
value = svalue
}
}
+3 -1
View File
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class D {
fun getValue(a: Any, p: PropertyMetadata) { }
fun getValue(a: Any, p: KProperty<*>) { }
}
object P {
@@ -1,6 +1,8 @@
import kotlin.reflect.KProperty
class Holder(var value: Int) {
fun getValue(that: Any?, desc: PropertyMetadata) = value
fun setValue(that: Any?, desc: PropertyMetadata, newValue: Int) { value = newValue }
fun getValue(that: Any?, desc: KProperty<*>) = value
fun setValue(that: Any?, desc: KProperty<*>, newValue: Int) { value = newValue }
}
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>(){
fun getValue(thisRef: Any?, prop: PropertyMetadata): T = notImplemented()
fun setValue(thisRef: Any?, prop: PropertyMetadata, value: T) = notImplemented()
fun getValue(thisRef: Any?, prop: KProperty<*>): T = notImplemented()
fun setValue(thisRef: Any?, prop: KProperty<*>, value: T) = notImplemented()
}
fun notImplemented() : Nothing = notImplemented()
+4 -2
View File
@@ -1,12 +1,14 @@
import kotlin.reflect.KProperty
// java.lang.ClassNotFoundException: kotlin.Nothing
var currentAccountId: Int? by SessionAccessor()
class SessionAccessor<T> {
fun getValue(o : Nothing?, desc: PropertyMetadata): T {
fun getValue(o : Nothing?, desc: KProperty<*>): 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)
annotation class First
@@ -7,11 +9,11 @@ class MyClass() {
}
class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): String {
fun getValue(t: Any?, p: KProperty<*>): String {
return "OK"
}
fun setValue(t: Any?, p: PropertyMetadata, i: String) {}
fun setValue(t: Any?, p: KProperty<*>, i: String) {}
}
fun box(): String {
@@ -1,3 +1,5 @@
import kotlin.reflect.KProperty
val four: Int by NumberDecrypter
class A {
@@ -5,7 +7,7 @@ class A {
}
object NumberDecrypter {
fun getValue(instance: Any?, data: PropertyMetadata) = when (data.name) {
fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
"four" -> 4
"two" -> 2
else -> throw AssertionError()
@@ -1,13 +1,15 @@
import kotlin.reflect.KProperty
var result: String by Delegate
object Delegate {
var value = "lol"
fun getValue(instance: Any?, data: PropertyMetadata): String {
fun getValue(instance: Any?, data: KProperty<*>): String {
return value
}
fun setValue(instance: Any?, data: PropertyMetadata, newValue: String) {
fun setValue(instance: Any?, data: KProperty<*>, newValue: String) {
value = newValue
}
}
@@ -1,6 +1,7 @@
//For KT-6020
import kotlin.reflect.KProperty1
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KProperty
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
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)
}
}
@@ -1,4 +1,5 @@
import kotlin.test.assertEquals
import kotlin.reflect.KProperty
class Project {
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 x1: Int by project
@@ -1,3 +1,5 @@
import kotlin.reflect.KProperty
class C {
// All these properties should have corresponding accessors
private val valWithGet: String
@@ -25,7 +27,7 @@ class C {
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
import kotlin.reflect.KProperty
annotation class Anno
class Class {
@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
import kotlin.reflect.KProperty
annotation class Anno
@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
package test
import kotlin.reflect.KProperty
class A {
var a by MyProperty()
}
class MyProperty<T> {
fun getValue(t: T, p: PropertyMetadata): Int = 42
fun setValue(t: T, p: PropertyMetadata, i: Int) {}
}
fun getValue(t: T, p: KProperty<*>): Int = 42
fun setValue(t: T, p: KProperty<*>, i: Int) {}
}
@@ -9,6 +9,6 @@ public final class A {
public final class 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 setValue(/*0*/ t: T, /*1*/ p: kotlin.PropertyMetadata, /*2*/ i: kotlin.Int): kotlin.Unit
public final fun getValue(/*0*/ t: T, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Int
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() {
public var x: Int by Delegate()
private set
}
class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int {
fun getValue(t: Any?, p: KProperty<*>): Int {
return 1
}
fun setValue(t: Any?, p: PropertyMetadata, i: Int) {}
fun setValue(t: Any?, p: KProperty<*>, i: Int) {}
}
// TESTED_OBJECT_KIND: function
@@ -1,9 +1,11 @@
import kotlin.reflect.KProperty
class TestDelegate() {
fun getValue(thisRef: Any?, desc: PropertyMetadata): Int {
fun getValue(thisRef: Any?, desc: KProperty<*>): Int {
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() {
fun getValue(thisRef: Any?, desc: PropertyMetadata): Int {
fun getValue(thisRef: Any?, desc: KProperty<*>): Int {
return 10
}
}
@@ -1,14 +1,16 @@
import kotlin.reflect.KProperty
public open class TestDelegate<T: Any>(private val initializer: () -> T) {
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) {
value = initializer()
}
return value!!
}
public open fun setValue(thisRef: Any?, desc: PropertyMetadata, svalue : T) {
public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : T) {
value = svalue
}
}
@@ -28,4 +30,4 @@ class Test {
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$delegate
// FLAGS: ACC_STATIC, ACC_PRIVATE, ACC_FINAL
// FLAGS: ACC_STATIC, ACC_PRIVATE, ACC_FINAL
@@ -1,14 +1,16 @@
import kotlin.reflect.KProperty
public open class TestDelegate<T: Any>(private val initializer: () -> T) {
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) {
value = initializer()
}
return value!!
}
public open fun setValue(thisRef: Any?, desc: PropertyMetadata, svalue : T) {
public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : T) {
value = svalue
}
}
@@ -1,9 +1,11 @@
import kotlin.reflect.KProperty
class TestDelegate() {
fun getValue(thisRef: Any?, desc: PropertyMetadata): Int {
fun getValue(thisRef: Any?, desc: KProperty<*>): Int {
return 10
}
public open fun setValue(thisRef: Any?, desc: PropertyMetadata, svalue : Int) {
public open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : Int) {
}
}
@@ -28,4 +30,4 @@ interface Test {
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$delegate
// ABSENT: TRUE
// ABSENT: TRUE
@@ -1,5 +1,7 @@
import kotlin.reflect.KProperty
class TestDelegate() {
fun getValue(thisRef: Any?, desc: PropertyMetadata): Int {
fun getValue(thisRef: Any?, desc: KProperty<*>): Int {
return 10
}
}
@@ -24,4 +26,4 @@ interface Test {
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$delegate
// ABSENT: TRUE
// ABSENT: TRUE
@@ -1,8 +1,10 @@
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
package foo
import kotlin.reflect.KProperty
object NumberDecrypter {
fun getValue(instance: Any?, data: PropertyMetadata) = when (data.name) {
fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
"four" -> 4
"two" -> 2
else -> throw Exception()
@@ -1,14 +1,16 @@
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
package foo
import kotlin.reflect.KProperty
object Delegate {
var value = "lol"
fun getValue(instance: Any?, data: PropertyMetadata): String {
fun getValue(instance: Any?, data: KProperty<*>): String {
return value
}
fun setValue(instance: Any?, data: PropertyMetadata, newValue: String) {
fun setValue(instance: Any?, data: KProperty<*>, newValue: String) {
value = newValue
}
}
@@ -1,5 +1,7 @@
package foo
import kotlin.reflect.KProperty
class State(var realValue: Int)
fun format(event: String, property: String, value: Int): String
@@ -8,12 +10,12 @@ fun format(event: String, property: String, value: Int): String
object LoggerDelegate {
var log = ""
fun getValue(state: State, desc: PropertyMetadata): Int {
fun getValue(state: State, desc: KProperty<*>): Int {
log += format("get", desc.name, 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)
state.realValue = value
}
@@ -36,4 +38,4 @@ fun box(): String {
assertEquals(expectedLog, LoggerDelegate.log)
return "OK"
}
}
@@ -1,9 +1,11 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) {
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i
}
}
@@ -1,9 +1,11 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) {
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i
}
}
@@ -1,9 +1,11 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) {
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i
}
}
@@ -1,9 +1,11 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
}
fun Delegate.getValue(t: Any?, p: PropertyMetadata): Int = 1
fun Delegate.getValue(t: Any?, p: KProperty<*>): Int = 1
class A {
val prop: Int by Delegate()
@@ -1,14 +1,16 @@
package foo
import kotlin.reflect.KProperty
interface WithName {
var name: String
}
class GetPropertyName() {
fun getValue(withName: WithName, property: PropertyMetadata): String {
fun getValue(withName: WithName, property: KProperty<*>): String {
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
}
}
@@ -1,11 +1,13 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
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
}
+4 -2
View File
@@ -1,14 +1,16 @@
package foo
import kotlin.reflect.KProperty
interface WithNumber {
var number: Int
}
class IncNumber(val inc: Int) {
fun getValue(withNumber: WithNumber, property: PropertyMetadata): Int {
fun getValue(withNumber: WithNumber, property: KProperty<*>): Int {
return withNumber.number + inc;
}
fun setValue(withNumber: WithNumber, property: PropertyMetadata, value: Int) {
fun setValue(withNumber: WithNumber, property: KProperty<*>, value: Int) {
withNumber.number = value;
}
}
@@ -1,7 +1,9 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
fun getValue(t: Any?, p: PropertyMetadata): Int = 1
fun getValue(t: Any?, p: KProperty<*>): Int = 1
}
val prop: Int by Delegate()
@@ -1,9 +1,11 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
fun getValue(t: Any?, p: PropertyMetadata): Int = inner
fun setValue(t: Any?, p: PropertyMetadata, i: Int) {
fun getValue(t: Any?, p: KProperty<*>): Int = inner
fun setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i
}
}
@@ -1,18 +1,20 @@
package foo
import kotlin.reflect.KProperty
interface Getter<T> {
fun get(): T
}
class Delegate<T>(val getter: Getter<T>) {
var t: T? = null
fun getValue(obj: Any, property: PropertyMetadata): T {
fun getValue(obj: Any, property: KProperty<*>): T {
if (t != null) {
return t!!
}
return getter.get()
}
fun setValue(obj: Any, property: PropertyMetadata, value: T) {
fun setValue(obj: Any, property: KProperty<*>, value: T) {
t = value
}
}
@@ -1,5 +1,7 @@
package foo
import kotlin.reflect.KProperty
class State(var value: Int)
interface Base {
@@ -7,9 +9,9 @@ interface Base {
}
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
}
@@ -37,4 +39,4 @@ fun box(): String {
assertEquals(10, d.getValueMultiplied(state))
return "OK"
}
}