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:
+12
@@ -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()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
class Local {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
val ref = Local::foo
|
||||
return Local().ref()
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
|
||||
fun changeToOK() { result = "OK" }
|
||||
|
||||
val ok = ::changeToOK
|
||||
ok()
|
||||
return result
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
class A {
|
||||
val result = "OK"
|
||||
}
|
||||
|
||||
return (::A)().result
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
class A {
|
||||
var result: String = "Fail";
|
||||
{
|
||||
result = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
return (::A)().result
|
||||
}
|
||||
+11
@@ -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)()
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
class A
|
||||
fun A.foo() = "OK"
|
||||
return (::A)().(A::foo)()
|
||||
}
|
||||
+4
@@ -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"
|
||||
}
|
||||
+11
@@ -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
|
||||
}
|
||||
+8
@@ -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")
|
||||
}
|
||||
+11
@@ -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()
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
fun foo(): String {
|
||||
fun bar() = "OK"
|
||||
val ref = ::bar
|
||||
return ref()
|
||||
}
|
||||
|
||||
val ref = ::foo
|
||||
return ref()
|
||||
}
|
||||
+7
@@ -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)()
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
val result = "OK"
|
||||
|
||||
fun foo() = result
|
||||
|
||||
return (::foo)()
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun box(): String {
|
||||
fun foo(s: String) = s
|
||||
return (::foo)("OK")
|
||||
}
|
||||
+15
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user