Introduce module 'reflection', move KFunctionN to it

Metadata for KFunction classes is now longer serialized along with built-in
classes. This effectively means that it's no longer possible to find KFunction
classes via dependency on built-ins. There should be a kotlin-runtime library
in the specified classpath for reflection types to be resolvable.

A lot of tests were moved and changed, because tests on callable references
require stdlib in classpath from now on
This commit is contained in:
Alexander Udalov
2014-05-07 18:35:45 +04:00
parent c1cd8bf069
commit c7a7f31e82
124 changed files with 619 additions and 847 deletions
@@ -0,0 +1,12 @@
class Outer {
val result = "OK"
inner class Inner {
fun foo() = result
}
}
fun box(): String {
val f = Outer.Inner::foo
return Outer().Inner().f()
}
@@ -0,0 +1,8 @@
fun box(): String {
class Local {
fun foo() = "OK"
}
val ref = Local::foo
return Local().ref()
}
@@ -0,0 +1,9 @@
fun box(): String {
var result = "Fail"
fun changeToOK() { result = "OK" }
val ok = ::changeToOK
ok()
return result
}
@@ -0,0 +1,7 @@
fun box(): String {
class A {
val result = "OK"
}
return (::A)().result
}
@@ -0,0 +1,10 @@
fun box(): String {
class A {
var result: String = "Fail";
{
result = "OK"
}
}
return (::A)().result
}
@@ -0,0 +1,11 @@
fun box(): String {
trait Named {
fun name(): String
}
enum class E : Named {
OK
}
return E.OK.(Named::name)()
}
@@ -0,0 +1,6 @@
class A
fun box(): String {
fun A.foo() = "OK"
return A().(A::foo)()
}
@@ -0,0 +1,5 @@
fun box(): String {
class A
fun A.foo() = "OK"
return (::A)().(A::foo)()
}
@@ -0,0 +1,4 @@
fun box(): String {
fun Int.is42With(that: Int) = this + 2 * that == 42
return if (16.(Int::is42With)(13)) "OK" else "Fail"
}
@@ -0,0 +1,11 @@
class A
fun box(): String {
var result = "Fail"
fun A.ext() { result = "OK" }
val f = A::ext
A().f()
return result
}
@@ -0,0 +1,8 @@
fun box(): String {
class Id<T> {
fun invoke(t: T) = t
}
val ref = Id<String>::invoke
return Id<String>().ref("OK")
}
@@ -0,0 +1,11 @@
fun box(): String {
val result = "OK"
class Local {
fun foo() = result
}
val member = Local::foo
val instance = Local()
return instance.member()
}
@@ -0,0 +1,10 @@
fun box(): String {
fun foo(): String {
fun bar() = "OK"
val ref = ::bar
return ref()
}
val ref = ::foo
return ref()
}
@@ -0,0 +1,7 @@
fun foo(until: Int): String {
fun bar(x: Int): String =
if (x == until) "OK" else bar(x + 1)
return (::bar)(0)
}
fun box() = foo(10)
@@ -0,0 +1,4 @@
fun box(): String {
fun foo() = "OK"
return (::foo)()
}
@@ -0,0 +1,7 @@
fun box(): String {
val result = "OK"
fun foo() = result
return (::foo)()
}
@@ -0,0 +1,4 @@
fun box(): String {
fun foo(s: String) = s
return (::foo)("OK")
}
@@ -0,0 +1,15 @@
var state = 23
fun box(): String {
fun incrementState(inc: Int) {
state += inc
}
val inc = ::incrementState
inc(12)
inc(-5)
inc(27)
inc(-15)
return if (state == 42) "OK" else "Fail $state"
}