Support bound function reference inlining
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun test(a: String, b: String, c: () -> String): String {
|
||||
return a + b + c();
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
var res = ""
|
||||
|
||||
fun String.id() = this
|
||||
|
||||
val receiver: String
|
||||
get() {
|
||||
res += "L"
|
||||
return "L"
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
res = ""
|
||||
var call = test(b = { res += "K"; "K" }(), a = { res += "O"; "O" }(), c = receiver::id)
|
||||
if (res != "KOL" || call != "OKL") return "fail 1: $res != KOL or $call != OKL"
|
||||
|
||||
res = ""
|
||||
call = test(b = { res += "K"; "K" }(), c = receiver::id, a = { res += "O"; "O" }())
|
||||
if (res != "KLO" || call != "OKL") return "fail 2: $res != KLO or $call != OKL"
|
||||
|
||||
|
||||
res = ""
|
||||
call = test(c = receiver::id, b = { res += "K"; "K" }(), a = { res += "O"; "O" }())
|
||||
if (res != "LKO" || call != "OKL") return "fail 3: $res != LKO or $call != OKL"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun test(a: String, b: Long, c: () -> String): String {
|
||||
return a + b + c();
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
var res = ""
|
||||
|
||||
fun String.id() = this
|
||||
|
||||
val receiver: String
|
||||
get() {
|
||||
res += "L"
|
||||
return "L"
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
res = ""
|
||||
var call = test(b = { res += "K"; 1L }(), a = { res += "O"; "O" }(), c = receiver::id)
|
||||
if (res != "KOL" || call != "O1L") return "fail 1: $res != KOL or $call != O1L"
|
||||
|
||||
res = ""
|
||||
call = test(b = { res += "K"; 1L }(), c = receiver::id, a = { res += "O"; "O" }())
|
||||
if (res != "KLO" || call != "O1L") return "fail 2: $res != KLO or $call != O1L"
|
||||
|
||||
|
||||
res = ""
|
||||
call = test(c = receiver::id, b = { res += "K"; 1L }(), a = { res += "O"; "O" }())
|
||||
if (res != "LKO" || call != "O1L") return "fail 3: $res != LKO or $call != O1L"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun go(f: () -> String) = f()
|
||||
|
||||
fun String.id(): String = this
|
||||
|
||||
fun foo(x: String, y: String): String {
|
||||
return go((x + y)::id)
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun box() = foo("O", "K")
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun foo(x: () -> String, z: String) = x() + z
|
||||
|
||||
fun String.id() = this
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun String.test() : String {
|
||||
return foo(this::id, "K")
|
||||
}
|
||||
|
||||
|
||||
fun box() : String {
|
||||
return "O".test()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun stub(f: () -> String): String = f()
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
class A(val z: String) {
|
||||
fun filter(s: String) = z == s
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val a = A("OK")
|
||||
val s = arrayOf("OK")
|
||||
return s.filter(a::filter).first()
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun foo(x: (String) -> String, z: String) = x(z)
|
||||
|
||||
fun String.id() = this
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun box() : String {
|
||||
var zeroSlot = "fail";
|
||||
val z = "O"
|
||||
return foo(z::plus, "K")
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun stub(f: () -> String): String = f()
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
class A(val z: String) {
|
||||
fun map(s: String) = z + s
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val a = A("O")
|
||||
val s = arrayOf("K")
|
||||
return s.map(a::map).first()
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun foo(x: () -> String, z: String) = x() + z
|
||||
|
||||
fun String.id() = this
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun box() : String {
|
||||
var zeroSlot = "fail";
|
||||
val z = "O"
|
||||
return foo(z::id, "K")
|
||||
}
|
||||
Reference in New Issue
Block a user