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,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()
}