Support :: references to properties in frontend

#KT-1183 In Progress
This commit is contained in:
Alexander Udalov
2014-05-08 22:28:07 +04:00
parent 52dadfc264
commit aa4d6a4ea7
22 changed files with 584 additions and 39 deletions
@@ -0,0 +1,32 @@
trait Base {
val x: Any
}
class A : Base {
override val x: String = ""
}
open class B : Base {
override val x: Number = 1.0
}
class C : B() {
override val x: Int = 42
}
fun test() {
val base = Base::x
base : KMemberProperty<Base, Any>
base.get(A()) : Any
<!TYPE_MISMATCH!>base.get(B())<!> : Number
<!TYPE_MISMATCH!>base.get(C())<!> : Int
val a = A::x
a : KMemberProperty<A, String>
a.get(A()) : String
<!TYPE_MISMATCH!>a.get(<!TYPE_MISMATCH!>B()<!>)<!> : Number
val b = B::x
b : KMemberProperty<B, Number>
<!TYPE_MISMATCH!>b.get(C())<!> : Int
}
@@ -0,0 +1,11 @@
open class Base {
val foo: Int = 42
}
open class Derived : Base()
fun test() {
val o = Base::foo
o : KMemberProperty<Base, Int>
o.get(Derived()) : Int
}
@@ -0,0 +1,8 @@
class A(var g: A) {
val f: Int = 0
fun test() {
::f : KMemberProperty<A, Int>
::g : KMutableMemberProperty<A, A>
}
}
@@ -0,0 +1,11 @@
class A {
fun test() {
::foo : KExtensionProperty<A, String>
::bar : KMutableExtensionProperty<A, Int>
}
}
val A.foo: String get() = ""
var A.bar: Int
get() = 42
set(value) { }
@@ -0,0 +1,22 @@
val String.countCharacters: Int
get() = length
var Int.meaning: Long
get() = 42L
set(value) {}
fun test() {
val f = String::countCharacters
f : KExtensionProperty<String, Int>
<!TYPE_MISMATCH!>f<!> : KMutableExtensionProperty<String, Int>
f.get("abc") : Int
f.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>set<!>("abc", 0)
val g = Int::meaning
g : KExtensionProperty<Int, Long>
g : KMutableExtensionProperty<Int, Long>
g.get(0) : Long
g.set(1, 0L)
}
@@ -0,0 +1,8 @@
val Any?.meaning: Int
get() = 42
fun test() {
val f = Any?::meaning
f.get(null) : Int
f.get("") : Int
}
@@ -0,0 +1,12 @@
class A<T>(val t: T) {
val foo: T = t
}
fun bar() {
val x = A<String>::foo
x : KMemberProperty<A<String>, String>
x : KMemberProperty<A<String>, Any?>
val y = A<*>::foo
y : KMemberProperty<A<*>, Any?>
}
@@ -0,0 +1,23 @@
// FILE: JavaClass.java
public class JavaClass {
public final int publicFinal;
public long publicMutable;
protected final double protectedFinal;
protected char protectedMutable;
private final String privateFinal;
private Object privateMutable;
}
// FILE: test.kt
fun test() {
JavaClass::publicFinal : KMemberProperty<JavaClass, Int>
JavaClass::publicMutable : KMutableMemberProperty<JavaClass, Long>
JavaClass::protectedFinal : KMemberProperty<JavaClass, Double>
JavaClass::protectedMutable : KMutableMemberProperty<JavaClass, Char>
JavaClass::<!INVISIBLE_MEMBER!>privateFinal<!> : KMemberProperty<JavaClass, String?>
JavaClass::<!INVISIBLE_MEMBER!>privateMutable<!> : KMutableMemberProperty<JavaClass, Any?>
}
@@ -0,0 +1,25 @@
// FILE: JavaClass.java
public class JavaClass {
public static final String publicFinal;
public static volatile Object publicMutable;
protected static final double protectedFinal;
protected static char protectedMutable;
private static final JavaClass privateFinal;
private static Throwable privateMutable;
}
// FILE: test.kt
import JavaClass.*
fun test() {
::publicFinal : KTopLevelProperty<String>
::publicMutable : KMutableTopLevelProperty<Any?>
::protectedFinal : KProperty<Double>
::protectedMutable : KMutableProperty<Char>
::<!INVISIBLE_MEMBER!>privateFinal<!> : KProperty<JavaClass?>
::<!INVISIBLE_MEMBER!>privateMutable<!> : KMutableProperty<Throwable?>
}
@@ -0,0 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun test(param: String) {
val a = ::<!UNSUPPORTED!>param<!>
val local = "local"
val b = ::<!UNSUPPORTED!>local<!>
val lambda = { -> }
val g = ::<!UNSUPPORTED!>lambda<!>
}
@@ -0,0 +1,19 @@
class A {
val foo: Unit = Unit.VALUE
var bar: String = ""
var self: A
get() = this
set(value) { }
}
fun A.test() {
val x = ::foo
val y = ::bar
val z = ::self
x : KMemberProperty<A, Unit>
y : KMutableMemberProperty<A, String>
z : KMutableMemberProperty<A, A>
y.set(z.get(A()), x.get(A()).toString())
}
@@ -0,0 +1,21 @@
class A {
val foo: Int = 42
var bar: String = ""
}
fun test() {
val p = A::foo
p : KMemberProperty<A, Int>
<!TYPE_MISMATCH!>p<!> : KMutableMemberProperty<A, Int>
p.get(A()) : Int
p.get(<!NO_VALUE_FOR_PARAMETER!>)<!>
p.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>set<!>(A(), 239)
val q = A::bar
q : KMemberProperty<A, String>
q : KMutableMemberProperty<A, String>
q.get(A()): String
q.set(A(), "q")
}
@@ -0,0 +1,28 @@
var x: Int = 42
val y: String get() = "y"
fun testX() {
val xx = ::x
xx : KMutableTopLevelProperty<Int>
xx : KTopLevelProperty<Int>
xx : KMutableProperty<Int>
xx : KProperty<Int>
xx : KCallable<Int>
xx.name : String
xx.get() : Int
xx.set(239)
}
fun testY() {
val yy = ::y
<!TYPE_MISMATCH!>yy<!> : KMutableTopLevelProperty<String>
yy : KTopLevelProperty<String>
<!TYPE_MISMATCH!>yy<!> : KMutableProperty<String>
yy : KProperty<String>
yy : KCallable<String>
yy.name : String
yy.get() : String
yy.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>set<!>("yy")
}