Support local function references in codegen

#KT-3704 In Progress
 #KT-1183 In Progress
This commit is contained in:
Alexander Udalov
2013-12-17 23:14:43 +04:00
parent 07648583ed
commit 363fe607fc
11 changed files with 179 additions and 14 deletions
@@ -0,0 +1,8 @@
fun box(): String {
class Local {
fun foo() = "OK"
}
val ref = Local::foo
return Local().ref()
}
@@ -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,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,10 @@
fun box(): String {
fun foo(): String {
fun bar() = "OK"
val ref = ::bar
return ref()
}
val ref = ::foo
return ref()
}
@@ -0,0 +1,4 @@
fun box(): String {
fun foo() = "OK"
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"
}