Simplify property hierarchy in reflection
Leave only 3*2 = 6 classes: KProperty0, KProperty1, KProperty2 and their mutable analogs, depending on the number of receivers a property takes
This commit is contained in:
Vendored
+4
-4
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.KMemberProperty
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
interface Base {
|
||||
val x: Any
|
||||
@@ -20,17 +20,17 @@ class C : B() {
|
||||
|
||||
fun test() {
|
||||
val base = Base::x
|
||||
checkSubtype<KMemberProperty<Base, Any>>(base)
|
||||
checkSubtype<KProperty1<Base, Any>>(base)
|
||||
checkSubtype<Any>(base.get(A()))
|
||||
checkSubtype<Number>(<!TYPE_MISMATCH!>base.get(B())<!>)
|
||||
checkSubtype<Int>(<!TYPE_MISMATCH!>base.get(C())<!>)
|
||||
|
||||
val a = A::x
|
||||
checkSubtype<KMemberProperty<A, String>>(a)
|
||||
checkSubtype<KProperty1<A, String>>(a)
|
||||
checkSubtype<String>(a.get(A()))
|
||||
checkSubtype<Number>(<!TYPE_MISMATCH!>a.get(<!TYPE_MISMATCH!>B()<!>)<!>)
|
||||
|
||||
val b = B::x
|
||||
checkSubtype<KMemberProperty<B, Number>>(b)
|
||||
checkSubtype<KProperty1<B, Number>>(b)
|
||||
checkSubtype<Int>(<!TYPE_MISMATCH!>b.get(C())<!>)
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.KMemberProperty
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
open class Base {
|
||||
val foo: Int = 42
|
||||
@@ -10,6 +10,6 @@ open class Derived : Base()
|
||||
|
||||
fun test() {
|
||||
val o = Base::foo
|
||||
checkSubtype<KMemberProperty<Base, Int>>(o)
|
||||
checkSubtype<KProperty1<Base, Int>>(o)
|
||||
checkSubtype<Int>(o.get(Derived()))
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ class A(var g: A) {
|
||||
val f: Int = 0
|
||||
|
||||
fun test() {
|
||||
val fRef: KMemberProperty<A, Int> = ::f
|
||||
val gRef: KMutableMemberProperty<A, A> = ::g
|
||||
val fRef: KProperty1<A, Int> = ::f
|
||||
val gRef: KMutableProperty1<A, A> = ::g
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
fun test() {
|
||||
val fooRef: KExtensionProperty<A, String> = ::foo
|
||||
val barRef: KMutableExtensionProperty<A, Int> = ::bar
|
||||
val fooRef: KProperty1<A, String> = ::foo
|
||||
val barRef: KMutableProperty1<A, Int> = ::bar
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-7
@@ -12,18 +12,14 @@ var Int.meaning: Long
|
||||
fun test() {
|
||||
val f = String::countCharacters
|
||||
|
||||
checkSubtype<KTopLevelExtensionProperty<String, Int>>(f)
|
||||
checkSubtype<KExtensionProperty<String, Int>>(f)
|
||||
checkSubtype<KMutableExtensionProperty<String, Int>>(<!TYPE_MISMATCH!>f<!>)
|
||||
checkSubtype<KProperty1<String, Int>>(f)
|
||||
checkSubtype<KMutableProperty1<String, Int>>(<!TYPE_MISMATCH!>f<!>)
|
||||
checkSubtype<Int>(f.get("abc"))
|
||||
f.<!UNRESOLVED_REFERENCE!>set<!>("abc", 0)
|
||||
|
||||
val g = Int::meaning
|
||||
|
||||
checkSubtype<KTopLevelExtensionProperty<Int, Long>>(g)
|
||||
checkSubtype<KExtensionProperty<Int, Long>>(g)
|
||||
checkSubtype<KMutableTopLevelExtensionProperty<Int, Long>>(g)
|
||||
checkSubtype<KMutableExtensionProperty<Int, Long>>(g)
|
||||
checkSubtype<KMutableProperty1<Int, Long>>(g)
|
||||
checkSubtype<Long>(g.get(0))
|
||||
g.set(1, 0L)
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.KMemberProperty
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
class A<T>(val t: T) {
|
||||
val foo: T = t
|
||||
@@ -8,9 +8,9 @@ class A<T>(val t: T) {
|
||||
|
||||
fun bar() {
|
||||
val x = A<String>::foo
|
||||
checkSubtype<KMemberProperty<A<String>, String>>(x)
|
||||
checkSubtype<KMemberProperty<A<String>, Any?>>(x)
|
||||
checkSubtype<KProperty1<A<String>, String>>(x)
|
||||
checkSubtype<KProperty1<A<String>, Any?>>(x)
|
||||
|
||||
val y = A<*>::foo
|
||||
checkSubtype<KMemberProperty<A<*>, Any?>>(y)
|
||||
checkSubtype<KProperty1<A<*>, Any?>>(y)
|
||||
}
|
||||
|
||||
+6
-6
@@ -17,10 +17,10 @@ public class JavaClass {
|
||||
import kotlin.reflect.*
|
||||
|
||||
fun test() {
|
||||
val pubFinRef: KMemberProperty<JavaClass, Int> = JavaClass::publicFinal
|
||||
val pubMutRef: KMutableMemberProperty<JavaClass, Long> = JavaClass::publicMutable
|
||||
val protFinRef: KMemberProperty<JavaClass, Double> = JavaClass::protectedFinal
|
||||
val protMutRef: KMutableMemberProperty<JavaClass, Char> = JavaClass::protectedMutable
|
||||
val privFinRef: KMemberProperty<JavaClass, String?> = JavaClass::<!INVISIBLE_MEMBER!>privateFinal<!>
|
||||
val privMutRef: KMutableMemberProperty<JavaClass, Any?> = JavaClass::<!INVISIBLE_MEMBER!>privateMutable<!>
|
||||
val pubFinRef: KProperty1<JavaClass, Int> = JavaClass::publicFinal
|
||||
val pubMutRef: KMutableProperty1<JavaClass, Long> = JavaClass::publicMutable
|
||||
val protFinRef: KProperty1<JavaClass, Double> = JavaClass::protectedFinal
|
||||
val protMutRef: KMutableProperty1<JavaClass, Char> = JavaClass::protectedMutable
|
||||
val privFinRef: KProperty1<JavaClass, String?> = JavaClass::<!INVISIBLE_MEMBER!>privateFinal<!>
|
||||
val privMutRef: KMutableProperty1<JavaClass, Any?> = JavaClass::<!INVISIBLE_MEMBER!>privateMutable<!>
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,4 +1,3 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS:-UNUSED_VARIABLE
|
||||
// FILE: JavaClass.java
|
||||
|
||||
@@ -20,8 +19,8 @@ import JavaClass.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
fun test() {
|
||||
val pubFinRef: KTopLevelProperty<String> = ::publicFinal
|
||||
val pubMutRef: KMutableTopLevelProperty<Any?> = ::publicMutable
|
||||
val pubFinRef: KProperty0<String> = ::publicFinal
|
||||
val pubMutRef: KMutableProperty0<Any?> = ::publicMutable
|
||||
val protFinRef: KProperty<Double> = ::protectedFinal
|
||||
val protMutRef: KMutableProperty<Char> = ::protectedMutable
|
||||
val privFinRef: KProperty<JavaClass?> = ::<!INVISIBLE_MEMBER!>privateFinal<!>
|
||||
|
||||
@@ -6,7 +6,7 @@ class A(var g: A) {
|
||||
val f: Int = 0
|
||||
|
||||
fun test() {
|
||||
checkSubtype<KMemberProperty<A, Int>>(::f)
|
||||
checkSubtype<KMutableMemberProperty<A, A>>(::g)
|
||||
checkSubtype<KProperty1<A, Int>>(::f)
|
||||
checkSubtype<KMutableProperty1<A, A>>(::g)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import kotlin.reflect.KMemberProperty
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
class TestClass(var prop: Int)
|
||||
open class OtherClass
|
||||
fun OtherClass.test(prop: KMemberProperty<TestClass, Int>): Unit = throw Exception()
|
||||
fun OtherClass.test(prop: KProperty1<TestClass, Int>): Unit = throw Exception()
|
||||
class OtherClass2: OtherClass() {
|
||||
val result = test(TestClass::<!UNRESOLVED_REFERENCE!>result<!>)
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
internal fun OtherClass.test(/*0*/ prop: kotlin.reflect.KMemberProperty<TestClass, kotlin.Int>): kotlin.Unit
|
||||
internal fun OtherClass.test(/*0*/ prop: kotlin.reflect.KProperty1<TestClass, kotlin.Int>): kotlin.Unit
|
||||
|
||||
internal open class OtherClass {
|
||||
public constructor OtherClass()
|
||||
|
||||
+3
-3
@@ -15,9 +15,9 @@ fun A.test() {
|
||||
val y = ::bar
|
||||
val z = ::self
|
||||
|
||||
checkSubtype<KMemberProperty<A, Unit>>(x)
|
||||
checkSubtype<KMutableMemberProperty<A, String>>(y)
|
||||
checkSubtype<KMutableMemberProperty<A, A>>(z)
|
||||
checkSubtype<KProperty1<A, Unit>>(x)
|
||||
checkSubtype<KMutableProperty1<A, String>>(y)
|
||||
checkSubtype<KMutableProperty1<A, A>>(z)
|
||||
|
||||
y.set(z.get(A()), x.get(A()).toString())
|
||||
}
|
||||
|
||||
+4
-4
@@ -10,16 +10,16 @@ class A {
|
||||
fun test() {
|
||||
val p = A::foo
|
||||
|
||||
checkSubtype<KMemberProperty<A, Int>>(p)
|
||||
checkSubtype<KMutableMemberProperty<A, Int>>(<!TYPE_MISMATCH!>p<!>)
|
||||
checkSubtype<KProperty1<A, Int>>(p)
|
||||
checkSubtype<KMutableProperty1<A, Int>>(<!TYPE_MISMATCH!>p<!>)
|
||||
checkSubtype<Int>(p.get(A()))
|
||||
p.get(<!NO_VALUE_FOR_PARAMETER!>)<!>
|
||||
p.<!UNRESOLVED_REFERENCE!>set<!>(A(), 239)
|
||||
|
||||
val q = A::bar
|
||||
|
||||
checkSubtype<KMemberProperty<A, String>>(q)
|
||||
checkSubtype<KMutableMemberProperty<A, String>>(q)
|
||||
checkSubtype<KProperty1<A, String>>(q)
|
||||
checkSubtype<KMutableProperty1<A, String>>(q)
|
||||
checkSubtype<String>(q.get(A()))
|
||||
q.set(A(), "q")
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.KMemberProperty
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
class C {
|
||||
val baz: Int = 12
|
||||
@@ -9,5 +9,5 @@ class C {
|
||||
fun Int.baz() {}
|
||||
|
||||
fun test() {
|
||||
C::baz checkType { _<KMemberProperty<C, Int>>() }
|
||||
}
|
||||
C::baz checkType { _<KProperty1<C, Int>>() }
|
||||
}
|
||||
|
||||
+4
-7
@@ -7,12 +7,9 @@ val y: String get() = "y"
|
||||
|
||||
fun testX() {
|
||||
val xx = ::x
|
||||
checkSubtype<KMutableTopLevelProperty<Int>>(xx)
|
||||
checkSubtype<KMutableTopLevelVariable<Int>>(xx)
|
||||
checkSubtype<KTopLevelProperty<Int>>(xx)
|
||||
checkSubtype<KTopLevelVariable<Int>>(xx)
|
||||
checkSubtype<KMutableProperty0<Int>>(xx)
|
||||
checkSubtype<KProperty0<Int>>(xx)
|
||||
checkSubtype<KMutableProperty<Int>>(xx)
|
||||
checkSubtype<KMutableVariable<Int>>(xx)
|
||||
checkSubtype<KProperty<Int>>(xx)
|
||||
checkSubtype<KCallable<Int>>(xx)
|
||||
|
||||
@@ -23,8 +20,8 @@ fun testX() {
|
||||
|
||||
fun testY() {
|
||||
val yy = ::y
|
||||
checkSubtype<KMutableTopLevelProperty<String>>(<!TYPE_MISMATCH!>yy<!>)
|
||||
checkSubtype<KTopLevelVariable<String>>(yy)
|
||||
checkSubtype<KMutableProperty0<String>>(<!TYPE_MISMATCH!>yy<!>)
|
||||
checkSubtype<KProperty0<String>>(yy)
|
||||
checkSubtype<KMutableProperty<String>>(<!TYPE_MISMATCH!>yy<!>)
|
||||
checkSubtype<KProperty<String>>(yy)
|
||||
checkSubtype<KCallable<String>>(yy)
|
||||
|
||||
Reference in New Issue
Block a user