Codegen for callable reference expressions

#KT-1183 In Progress
This commit is contained in:
Alexander Udalov
2013-04-15 19:47:10 +04:00
parent 1eeaaad05d
commit 054e5fb5e7
46 changed files with 877 additions and 7 deletions
@@ -0,0 +1,9 @@
abstract class A {
abstract fun foo(): String
}
class B : A() {
override fun foo() = "OK"
}
fun box(): String = B().(A::foo)()
@@ -0,0 +1,5 @@
fun box(): String {
if (true.(Boolean::not)() != false) return "Fail 1"
if (false.(Boolean::not)() != true) return "Fail 2"
return "OK"
}
@@ -0,0 +1,11 @@
class A {
fun foo(k: Int) = k
fun result() = this.(::foo)(111)
}
fun box(): String {
val result = A().result()
if (result != 111) return "Fail $result"
return "OK"
}
@@ -0,0 +1,12 @@
class A {
fun o() = 111
fun k(k: Int) = k
}
fun A.foo() = this.(::o)() + this.(A::k)(222)
fun box(): String {
val result = A().foo()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,8 @@
class A {
fun foo() = "OK"
}
fun box(): String {
val x = A::foo
return A().x()
}
@@ -0,0 +1,8 @@
class A {
fun foo(result: String) = result
}
fun box(): String {
val x = A::foo
return A().x("OK")
}
@@ -0,0 +1,14 @@
class A {
var result = "Fail"
fun foo() {
result = "OK"
}
}
fun box(): String {
val a = A()
val x = A::foo
a.x()
return a.result
}
@@ -0,0 +1,14 @@
class A {
var result = "Fail"
fun foo(newResult: String) {
result = newResult
}
}
fun box(): String {
val a = A()
val x = A::foo
a.x("OK")
return a.result
}
@@ -0,0 +1,5 @@
class A {
var result = "OK"
}
fun box() = (::A)().result
@@ -0,0 +1,3 @@
class A(val result: String)
fun box() = (::A)("OK").result
@@ -0,0 +1,9 @@
enum class E {
I
}
fun box(): String {
val i = E.I.(E::name)()
if (i != "I") return "Fail $i"
return "OK"
}
@@ -0,0 +1,3 @@
class A
fun box() = if (A().(A::equals)(A())) "Fail" else "OK"
@@ -0,0 +1,7 @@
class A {
fun result() = this.(::foo)("OK")
}
fun A.foo(x: String) = x
fun box() = A().result()
@@ -0,0 +1,7 @@
class A
fun A.foo() = this.(A::bar)("OK")
fun A.bar(x: String) = x
fun box() = A().foo()
@@ -0,0 +1,8 @@
class A
fun A.foo() = "OK"
fun box(): String {
val x = A::foo
return A().x()
}
@@ -0,0 +1,8 @@
class A
fun A.foo(result: String) = result
fun box(): String {
val x = A::foo
return A().x("OK")
}
@@ -0,0 +1,14 @@
class A {
var result = "Fail"
}
fun A.foo() {
result = "OK"
}
fun box(): String {
val a = A()
val x = A::foo
a.x()
return a.result
}
@@ -0,0 +1,14 @@
class A {
var result = "Fail"
}
fun A.foo(newResult: String) {
result = newResult
}
fun box(): String {
val a = A()
val x = A::foo
a.x("OK")
return a.result
}
@@ -0,0 +1,5 @@
class A<T>(val t: T) {
fun foo(): T = t
}
fun box() = A("OK").(A<String>::foo)()
@@ -0,0 +1,14 @@
class A {
inner class Inner {
val o = 111
val k = 222
}
fun result() = this.(A::Inner)().o + this.(::Inner)().k
}
fun box(): String {
val result = A().result()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,14 @@
class A {
inner class Inner {
val o = 111
val k = 222
}
}
fun A.foo() = this.(A::Inner)().o + this.(::Inner)().k
fun box(): String {
val result = A().foo()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,12 @@
class A {
inner class Inner {
val o = 111
val k = 222
}
}
fun box(): String {
val result = (::A)().(A::Inner)().o + A().(A::Inner)().k
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,9 @@
class A {
inner class Inner(val result: Int)
}
fun box(): String {
val result = (::A)().(A::Inner)(111).result + A().(A::Inner)(222).result
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,14 @@
class A {
class Nested {
val o = 111
val k = 222
}
fun result() = (::Nested)().o + (A::Nested)().k
}
fun box(): String {
val result = A().result()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,7 @@
class A {
class Nested {
val result = "OK"
}
}
fun box() = (A::Nested)().result
@@ -0,0 +1,5 @@
class A {
class Nested(val result: String)
}
fun box() = (A::Nested)("OK").result
@@ -0,0 +1,11 @@
fun box(): String {
(::ByteArray)(10)
(::IntArray)(10)
(::ShortArray)(10)
(::LongArray)(10)
(::DoubleArray)(10)
(::FloatArray)(10)
(::BooleanArray)(10)
return "OK"
}
@@ -0,0 +1,19 @@
import java.util.ArrayList
import java.util.Arrays
import java.util.Collections
import java.util.Comparator
fun sort(list: MutableList<String>, comparator: (String, String) -> Int) {
Collections.sort(list, object : Comparator<String> {
override fun compare(p0: String, p1: String) = comparator(p0, p1)
})
}
fun compare(s1: String, s2: String) = s1 compareTo s2
fun box(): String {
val l = ArrayList(Arrays.asList("d", "b", "c", "e", "a"))
sort(l, ::compare)
if (l != Arrays.asList("a", "b", "c", "d", "e")) return "Fail: $l"
return "OK"
}
@@ -0,0 +1,11 @@
fun foo(o: Int, k: Int) = o + k
class A {
fun bar() = (::foo)(111, 222)
}
fun box(): String {
val result = A().bar()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,11 @@
fun foo(o: Int, k: Int) = o + k
class A
fun A.bar() = (::foo)(111, 222)
fun box(): String {
val result = A().bar()
if (result != 333) return "Fail $result"
return "OK"
}
@@ -0,0 +1,6 @@
fun foo() = "OK"
fun box(): String {
val x = ::foo
return x()
}
@@ -0,0 +1,6 @@
fun foo(x: String) = x
fun box(): String {
val x = ::foo
return x("OK")
}
@@ -0,0 +1,11 @@
var result = "Fail"
fun foo() {
result = "OK"
}
fun box(): String {
val x = ::foo
x()
return result
}
@@ -0,0 +1,11 @@
var result = "Fail"
fun foo(newResult: String) {
result = newResult
}
fun box(): String {
val x = ::foo
x("OK")
return result
}
@@ -0,0 +1,11 @@
trait T {
fun foo() = "OK"
}
class B : T {
inner class C {
fun bar() = this@B.(::foo)()
}
}
fun box() = B().C().bar()
@@ -0,0 +1,9 @@
trait A {
fun foo(): String
}
class B : A {
override fun foo() = "OK"
}
fun box() = B().(A::foo)()