JVM IR: Avoid direct invokes in callable reference tests

Due to the direct invoke optimization, most callable reference tests
were not generating callable references/lambdas.
This commit is contained in:
Steven Schäfer
2022-06-13 14:49:49 +02:00
committed by Alexander Udalov
parent f0238766df
commit 7d59c7689c
123 changed files with 216 additions and 208 deletions
@@ -1,4 +1,4 @@
fun box(): String {
return if ((arrayOf(1, 2, 3)::get)(1) == 2) "OK" else "Fail"
return if ((arrayOf(1, 2, 3)::get).let { it(1) } == 2) "OK" else "Fail"
}
@@ -5,4 +5,4 @@ class A {
}
}
fun box() = (A.Companion::ok)()
fun box() = (A.Companion::ok).let { it() }
@@ -7,11 +7,11 @@ class A {
val aMemberProperty: Int get() = 42.also { result += "A.amp," }
fun test(): String {
(::memberFunction)()
(::aExtensionFunction)()
(::memberFunction).let { it() }
(::aExtensionFunction).let { it() }
(::memberProperty)()
(::aExtensionProperty)()
(::memberProperty).let { it() }
(::aExtensionProperty).let { it() }
return result
}
@@ -21,17 +21,17 @@ class A {
val memberProperty: Int get() = 42.also { result += "B.mp," }
fun test(): String {
(::aMemberFunction)()
(::aExtensionFunction)()
(::aMemberFunction).let { it() }
(::aExtensionFunction).let { it() }
(::aMemberProperty)()
(::aExtensionProperty)()
(::aMemberProperty).let { it() }
(::aExtensionProperty).let { it() }
(::memberFunction)()
(::memberProperty)()
(::memberFunction).let { it() }
(::memberProperty).let { it() }
(::bExtensionFunction)()
(::bExtensionProperty)()
(::bExtensionFunction).let { it() }
(::bExtensionProperty).let { it() }
return result
}
@@ -53,28 +53,28 @@ fun box(): String {
result = ""
with(A()) {
(::memberFunction)()
(::aExtensionFunction)()
(::memberFunction).let { it() }
(::aExtensionFunction).let { it() }
(::memberProperty)()
(::aExtensionProperty)()
(::memberProperty).let { it() }
(::aExtensionProperty).let { it() }
}
if (result != "A.mf,A.ef,A.mp,A.ep,") return "Fail $result"
result = ""
with(A()) {
with(B()) {
(::aMemberFunction)()
(::aExtensionFunction)()
(::aMemberFunction).let { it() }
(::aExtensionFunction).let { it() }
(::aMemberProperty)()
(::aExtensionProperty)()
(::aMemberProperty).let { it() }
(::aExtensionProperty).let { it() }
(::memberFunction)()
(::memberProperty)()
(::memberFunction).let { it() }
(::memberProperty).let { it() }
(::bExtensionFunction)()
(::bExtensionProperty)()
(::bExtensionFunction).let { it() }
(::bExtensionProperty).let { it() }
}
}
if (result != "A.amf,A.ef,A.amp,A.ep,B.mf,B.mp,B.ef,B.ep,") return "Fail $result"
@@ -7,6 +7,6 @@ class Host {
fun box(): String {
Generic(Host()).p::class
(Generic(Host()).p::t)()
return (Generic(Host()).p::v)()
(Generic(Host()).p::t).let { it() }
return (Generic(Host()).p::v).let { it() }
}
@@ -3,13 +3,13 @@
fun box(): String {
val a = intArrayOf(1, 2)
val b = arrayOf("OK")
if ((a::component2)() != 2) {
if ((a::component2).let { it() } != 2) {
return "fail"
}
if ((a::get)(1) != 2) {
if ((a::get).let { it(1) } != 2) {
return "fail"
}
return (b::get)(0)
return (b::get).let { it(0) }
}
@@ -3,4 +3,4 @@ object Singleton {
fun ok() = "OK"
}
fun box() = (Singleton::ok)()
fun box() = (Singleton::ok).let { it() }
@@ -10,6 +10,7 @@ class A {
// FILE: 1.kt
fun box(): String {
(::A)(0.0, 0)
val constructor = ::A
constructor(0.0, 0)
return "OK"
}
@@ -6,4 +6,4 @@ class B : A() {
override fun foo() = "OK"
}
fun box(): String = (A::foo)(B())
fun box(): String = (A::foo).let { it(B()) }
@@ -1,5 +1,5 @@
fun box(): String {
if ((Boolean::not)(true) != false) return "Fail 1"
if ((Boolean::not)(false) != true) return "Fail 2"
if ((Boolean::not).let { it(true) } != false) return "Fail 1"
if ((Boolean::not).let { it(false) } != true) return "Fail 2"
return "OK"
}
@@ -1,7 +1,7 @@
class A {
fun foo(k: Int) = k
fun result() = (A::foo)(this, 111)
fun result() = (A::foo).let { it(this, 111) }
}
fun box(): String {
@@ -3,7 +3,7 @@ class A {
fun k(k: Int) = k
}
fun A.foo() = (A::o)(this) + (A::k)(this, 222)
fun A.foo() = (A::o).let { it(this) } + (A::k).let { it(this, 222) }
fun box(): String {
val result = A().foo()
@@ -2,4 +2,4 @@ class A {
var result = "OK"
}
fun box() = (::A)().result
fun box() = (::A).let { it() }.result
@@ -1,3 +1,3 @@
class A(val result: String)
fun box() = (::A)("OK").result
fun box() = (::A).let { it("OK") }.result
@@ -1,3 +1,3 @@
class A
fun box() = if ((A::equals)(A(), A())) "Fail" else "OK"
fun box() = if ((A::equals).let { it(A(), A()) }) "Fail" else "OK"
@@ -1,5 +1,5 @@
class A {
fun result() = (A::foo)(this, "OK")
fun result() = (A::foo).let { it(this, "OK") }
}
fun A.foo(x: String) = x
@@ -1,6 +1,6 @@
class A
fun A.foo() = (A::bar)(this, "OK")
fun A.foo() = (A::bar).let { it(this, "OK") }
fun A.bar(x: String) = x
@@ -2,4 +2,4 @@ class A<T>(val t: T) {
fun foo(): T = t
}
fun box() = (A<String>::foo)(A("OK"))
fun box() = (A<String>::foo).let { it(A("OK")) }
@@ -4,7 +4,7 @@ class A {
val k = 222
}
fun result() = (A::Inner)(this).o + (A::Inner)(this).k
fun result() = (A::Inner).let { it(this) }.o + (A::Inner).let { it(this) }.k
}
fun box(): String {
@@ -5,7 +5,7 @@ class A {
}
}
fun A.foo() = (A::Inner)(this).o + (A::Inner)(this).k
fun A.foo() = (A::Inner).let { it(this) }.o + (A::Inner).let { it(this) }.k
fun box(): String {
val result = A().foo()
@@ -6,7 +6,7 @@ class A {
}
fun box(): String {
val result = (A::Inner)((::A)()).o + (A::Inner)(A()).k
val result = (A::Inner).let { c -> c((::A).let { it() }).o } + (A::Inner).let { it(A()) }.k
if (result != 333) return "Fail $result"
return "OK"
}
@@ -3,7 +3,10 @@ class A {
}
fun box(): String {
val result = (A::Inner)((::A)(), 111).result + (A::Inner)(A(), 222).result
val result = (A::Inner).let { c -> c((::A).let { it() }, 111) }.result + (A::Inner).let { it(A(), 222) }.result
if (result != 333) return "Fail $result"
return "OK"
}
// CHECK_BYTECODE_TEXT
// 3 Function[^.\n]*\.invoke
@@ -10,6 +10,6 @@ fun box(): String {
numbers.add(1)
numbers.add(2)
numbers.add(3)
(Collections::rotate)(numbers, 1)
(Collections::rotate).let { it(numbers, 1) }
return if ("$numbers" == "[3, 1, 2]") "OK" else "Fail $numbers"
}
@@ -3,5 +3,5 @@ fun box(): String {
val result = "OK"
}
return (::A)().result
return (::A).let { it() }.result
}
@@ -6,5 +6,5 @@ fun box(): String {
}
}
return (::A)().result
return (::A).let { it() }.result
}
@@ -2,5 +2,5 @@ class A
fun box(): String {
fun A.foo() = "OK"
return (A::foo)(A())
return (A::foo).let { it(A()) }
}
@@ -1,5 +1,5 @@
fun box(): String {
class A
fun A.foo() = "OK"
return (A::foo)((::A)())
return (A::foo).let { c -> c((::A).let { it() }) }
}
@@ -1,4 +1,4 @@
fun box(): String {
fun Int.is42With(that: Int) = this + 2 * that == 42
return if ((Int::is42With)(16, 13)) "OK" else "Fail"
return if ((Int::is42With).let { it(16, 13) }) "OK" else "Fail"
}
@@ -1,7 +1,7 @@
fun foo(until: Int): String {
fun bar(x: Int): String =
if (x == until) "OK" else bar(x + 1)
return (::bar)(0)
return (::bar).let { it(0) }
}
fun box() = foo(10)
@@ -1,4 +1,4 @@
fun box(): String {
fun foo() = "OK"
return (::foo)()
return (::foo).let { it() }
}
@@ -3,5 +3,5 @@ fun box(): String {
fun foo() = result
return (::foo)()
return (::foo).let { it() }
}
@@ -1,4 +1,4 @@
fun box(): String {
fun foo(s: String) = s
return (::foo)("OK")
return (::foo).let { it("OK") }
}
@@ -4,7 +4,7 @@ class A {
val k = 222
}
fun result() = (::Nested)().o + (A::Nested)().k
fun result() = (::Nested).let { it() }.o + (A::Nested).let { it() }.k
}
fun box(): String {
@@ -4,4 +4,4 @@ class A {
}
}
fun box() = (A::Nested)().result
fun box() = (A::Nested).let { it() }.result
@@ -2,4 +2,4 @@ class A {
class Nested(val result: String)
}
fun box() = (A::Nested)("OK").result
fun box() = (A::Nested).let { it("OK") }.result
@@ -1,7 +1,7 @@
class A {
private fun foo() = "OK"
fun bar() = (A::foo)(this)
fun bar() = (A::foo).let { it(this) }
}
fun box() = A().bar()
@@ -5,7 +5,7 @@ fun <T> run(arg1: T, arg2: T, funRef:(T,T) -> T): T {
fun foo(o: Int, k: Int) = o + k
class A {
fun bar() = (::foo)(111, 222)
fun bar() = (::foo).let { it(111, 222) }
}
fun box(): String {
@@ -6,7 +6,7 @@ fun foo(o: Int, k: Int) = o + k
class A
fun A.bar() = (::foo)(111, 222)
fun A.bar() = (::foo).let { it(111, 222) }
fun box(): String {
val result = A().bar()
@@ -4,7 +4,7 @@ interface T {
class B : T {
inner class C {
fun bar() = (T::foo)(this@B)
fun bar() = (T::foo).let { it(this@B) }
}
}
@@ -6,4 +6,4 @@ class B : A {
override fun foo() = "OK"
}
fun box() = (A::foo)(B())
fun box() = (A::foo).let { it(B()) }
@@ -13,6 +13,6 @@ class A {
fun box(): String {
val args = arrayOf("Fail")
(A::main)(args)
(A::main).let { it(args) }
return args[0]
}
@@ -6,7 +6,7 @@ class C {
{
"".ext()
f()
}.invoke()
}.let { it.invoke() }
object : Runnable {
public override fun run() {
@@ -4,7 +4,7 @@ class C{
public fun foo() : Int {
{
v = v + 1
}.invoke()
}.let { it.invoke() }
object : Runnable {
public override fun run() {
+1 -1
View File
@@ -6,7 +6,7 @@ infix fun Int.foo(s: Int): Int {
return this + s
}
open class B : A({ 1 foo 2} ())
open class B : A({ 1 foo 2 }.let { it() })
fun box(): String {
return if (B().s == 3) "OK" else "Fail"
+1 -1
View File
@@ -3,7 +3,7 @@ class A {
init {
val flag = "OK"
fun getFlag(): String = flag
result = { getFlag() } ()
result = { getFlag() }.let { it() }
}
}
fun box(): String = A().result
+1 -1
View File
@@ -5,6 +5,6 @@ fun box(): String {
i++
} else {
}
}()
}.let { it() }
return "OK"
}
@@ -16,8 +16,8 @@ class A {
}
suspend fun test(): String {
(::memberFunction)()
(::aExtensionFunction)()
(::memberFunction).let { it() }
(::aExtensionFunction).let { it() }
return result
}
@@ -28,12 +28,12 @@ class A {
}
suspend fun test(): String {
(::aMemberFunction)()
(::aExtensionFunction)()
(::aMemberFunction).let { it() }
(::aExtensionFunction).let { it() }
(::memberFunction)()
(::memberFunction).let { it() }
(::bExtensionFunction)()
(::bExtensionFunction).let { it() }
return result
}
@@ -69,8 +69,8 @@ fun box(): String {
result = ""
builder {
with(A()) {
(::memberFunction)()
(::aExtensionFunction)()
(::memberFunction).let { it() }
(::aExtensionFunction).let { it() }
}
}
if (result != "A.mf,A.ef,") return "Fail $result"
@@ -79,12 +79,12 @@ fun box(): String {
builder {
with(A()) {
with(B()) {
(::aMemberFunction)()
(::aExtensionFunction)()
(::aMemberFunction).let { it() }
(::aExtensionFunction).let { it() }
(::memberFunction)()
(::memberFunction).let { it() }
(::bExtensionFunction)()
(::bExtensionFunction).let { it() }
}
}
}
@@ -2,7 +2,7 @@
import kotlin.coroutines.*
fun box(): String = a { (::write)() }
fun box(): String = a { (::write).let { it() } }
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
@@ -44,7 +44,7 @@ suspend fun fooCallableReference(until: Int): String {
val k = "K"
val dot = "."
suspend fun bar(x: Int): String =
if (x == until) dot else if (x < until) o + (::bar)(x * 2) else k + (::bar)(x - 1)
if (x == until) dot else if (x < until) o + (::bar).let { it(x * 2) } else k + (::bar).let { it(x - 1) }
return bar(1)
}
@@ -53,8 +53,8 @@ suspend fun fooCallableReferenceIndirectRecursion(until: Int): String {
val k = "K"
val dot = "."
suspend fun bar(x: Int): String {
suspend fun innerO() = o + (::bar)(x * 2)
suspend fun innerK() = k + (::bar)(x - 1)
suspend fun innerO() = o + (::bar).let { it(x * 2) }
suspend fun innerK() = k + (::bar).let { it(x - 1) }
return if (x == until) dot else if (x < until) innerO() else innerK()
}
return bar(1)
@@ -29,7 +29,7 @@ inline suspend fun K(block: suspend (String) -> String) = block("K")
suspend fun ok(o: String): String {
return o + run {
if (o != "K") {
(::ok)("K")
(::ok).let { it("K") }
} else ""
}
}
@@ -14,7 +14,7 @@ import foo.Foo
class Bar() : Foo() {
fun execute(): String {
return { foo() } ()
return { foo() }.let { it() }
}
}
@@ -8,5 +8,5 @@ fun box(): String {
object {
val keys = key
}.keys
} ()
}.let { it() }
}
@@ -1,6 +1,6 @@
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 Function(^.)*.invoke
// 0 invoke
class Outer (val x: String) {
inner class Inner(val y: String) {
@@ -1,6 +1,6 @@
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 Function(^.)*.invoke
// 0 invoke
class C(val x: String) {
fun foo(s: String) = x + s
@@ -1,6 +1,6 @@
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 Function(^.)*.invoke
// 0 invoke
class C(x: String, y: String) {
val yx = y + x
@@ -1,6 +1,6 @@
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 Function(^.)*.invoke
// 0 invoke
fun box() =
{ k: String ->
@@ -1,6 +1,6 @@
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 Function(^.)*.invoke
// 0 invoke
fun box() =
(fun (s: String): String {
@@ -1,6 +1,6 @@
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 Function(^.)*.invoke
// 0 invoke
fun ok(s: String) = "O" + s
@@ -1,6 +1,6 @@
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 Function(^.)*.invoke
// 0 invoke
fun box() =
{ s: String ->
@@ -1,6 +1,6 @@
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 Function(^.)*.invoke
// 0 invoke
class Outer (val x: String) {
inner class Inner(val y: String) {
@@ -1,2 +1,6 @@
// CHECK_BYTECODE_TEXT
// JVM_IR_TEMPLATES
// 0 invoke
fun box(): String =
(String::plus)("O", "K")
+1 -1
View File
@@ -4,7 +4,7 @@ fun result(r: String) { result = r }
object Foo {
private operator fun String.unaryPlus() = "(" + this + ")"
fun foo() = { result(+"Stuff") }()
fun foo() = { result(+"Stuff") }.let { it() }
}
fun box(): String {
@@ -13,8 +13,8 @@ fun B.test(): String {
if (foo()() != "##") return "fail3"
if (foo()(42) != "#42") return "fail4"
if ((foo())(42) != "#42") return "fail5"
if ({ -> A()}()() != "##") return "fail6"
if ({ -> A()}()(37) != "#37") return "fail7"
if ({ -> A()}.let { it() }() != "##") return "fail6"
if ({ -> A()}.let { it() }(37) != "#37") return "fail7"
return "OK"
}
@@ -14,7 +14,7 @@ fun box(): String {
if (foo()() != "##") return "fail3"
if (foo()(42) != "#42") return "fail4"
if ((foo())(42) != "#42") return "fail5"
if ({ -> A()}()() != "##") return "fail6"
if ({ -> A()}()(37) != "#37") return "fail7"
if ({ -> A()}.let { it() }() != "##") return "fail6"
if ({ -> A()}.let { it() }(37) != "#37") return "fail7"
return "OK"
}
+1 -1
View File
@@ -9,6 +9,6 @@ public class B(): A(){
public override fun method() : String {
return ({
super.method()
})()
}).let { it() }
}
}
@@ -3,7 +3,7 @@ fun outer() {
if (i > 0){
{
it: Int -> inner(0) // <- invocation of literal itself is generated instead
}.invoke(1)
}.let { it.invoke(1) }
}
}
inner(1)
@@ -14,7 +14,7 @@ fun box(): String {
{
foo(foo, 1)
foo("K")
} ()
}.let { it() }
}
return s
@@ -16,9 +16,9 @@ fun L.test() = x
fun S.test() = x
fun box(): String {
if (Z(42)::test.invoke() != 42) throw AssertionError()
if (L(1234L)::test.invoke() != 1234L) throw AssertionError()
if (S("abcdef")::test.invoke() != "abcdef") throw AssertionError()
if (Z(42)::test.let { it.invoke() } != 42) throw AssertionError()
if (L(1234L)::test.let { it.invoke() } != 1234L) throw AssertionError()
if (S("abcdef")::test.let { it.invoke() } != "abcdef") throw AssertionError()
return "OK"
}
@@ -16,9 +16,9 @@ fun L<Long>.test() = x
fun S<String>.test() = x
fun box(): String {
if (Z(42)::test.invoke() != 42) throw AssertionError()
if (L(1234L)::test.invoke() != 1234L) throw AssertionError()
if (S("abcdef")::test.invoke() != "abcdef") throw AssertionError()
if (Z(42)::test.let { it.invoke() } != 42) throw AssertionError()
if (L(1234L)::test.let { it.invoke() } != 1234L) throw AssertionError()
if (S("abcdef")::test.let { it.invoke() } != "abcdef") throw AssertionError()
return "OK"
}
@@ -18,9 +18,9 @@ value class S(val x: String) {
}
fun box(): String {
if (Z(42)::test.invoke() != 42) throw AssertionError()
if (L(1234L)::test.invoke() != 1234L) throw AssertionError()
if (S("abcdef")::test.invoke() != "abcdef") throw AssertionError()
if (Z(42)::test.let { it.invoke() } != 42) throw AssertionError()
if (L(1234L)::test.let { it.invoke() } != 1234L) throw AssertionError()
if (S("abcdef")::test.let { it.invoke() } != "abcdef") throw AssertionError()
return "OK"
}
@@ -18,9 +18,9 @@ value class S<T: String>(val x: T) {
}
fun box(): String {
if (Z(42)::test.invoke() != 42) throw AssertionError()
if (L(1234L)::test.invoke() != 1234L) throw AssertionError()
if (S("abcdef")::test.invoke() != "abcdef") throw AssertionError()
if (Z(42)::test.let { it.invoke() } != 42) throw AssertionError()
if (L(1234L)::test.let { it.invoke() } != 1234L) throw AssertionError()
if (S("abcdef")::test.let { it.invoke() } != "abcdef") throw AssertionError()
return "OK"
}
@@ -12,8 +12,8 @@ class Outer(val z1: Z) {
}
fun box(): String {
assertEquals(Z(1), ::Outer.invoke(Z(1)).z1)
assertEquals(Z(2), Outer::Inner.invoke(Outer(Z(1)), Z(2)).z2)
assertEquals(Z(1), ::Outer.let { it.invoke(Z(1)) }.z1)
assertEquals(Z(2), Outer::Inner.let { it.invoke(Outer(Z(1)), Z(2)) }.z2)
return "OK"
}
}
@@ -12,8 +12,8 @@ class Outer(val z1: Z<Int>) {
}
fun box(): String {
assertEquals(Z(1), ::Outer.invoke(Z(1)).z1)
assertEquals(Z(2), Outer::Inner.invoke(Outer(Z(1)), Z(2)).z2)
assertEquals(Z(1), ::Outer.let { it.invoke(Z(1)) }.z1)
assertEquals(Z(2), Outer::Inner.let { it.invoke(Outer(Z(1)), Z(2)) }.z2)
return "OK"
}
}
@@ -14,7 +14,7 @@ value class S(val x: String)
fun test(aZ: Z, aL: L, aS: S) = "${aZ.x} ${aL.x} ${aS.x}"
fun box(): String {
if (::test.invoke(Z(1), L(1L), S("abc")) != "1 1 abc") throw AssertionError()
if (::test.let { it.invoke(Z(1), L(1L), S("abc")) } != "1 1 abc") throw AssertionError()
return "OK"
}
@@ -14,7 +14,7 @@ value class S<T: String>(val x: T)
fun test(aZ: Z<Int>, aL: L<Long>, aS: S<String>) = "${aZ.x} ${aL.x} ${aS.x}"
fun box(): String {
if (::test.invoke(Z(1), L(1L), S("abc")) != "1 1 abc") throw AssertionError()
if (::test.let { it.invoke(Z(1), L(1L), S("abc")) } != "1 1 abc") throw AssertionError()
return "OK"
}
@@ -16,9 +16,9 @@ fun L.test() = x
fun S.test() = x
fun box(): String {
if (Z::test.invoke(Z(42)) != 42) throw AssertionError()
if (L::test.invoke(L(1234L)) != 1234L) throw AssertionError()
if (S::test.invoke(S("abcdef")) != "abcdef") throw AssertionError()
if (Z::test.let { it.invoke(Z(42)) } != 42) throw AssertionError()
if (L::test.let { it.invoke(L(1234L)) } != 1234L) throw AssertionError()
if (S::test.let { it.invoke(S("abcdef")) } != "abcdef") throw AssertionError()
return "OK"
}
@@ -16,9 +16,9 @@ fun L<Long>.test() = x
fun S<String>.test() = x
fun box(): String {
if (Z<Int>::test.invoke(Z(42)) != 42) throw AssertionError()
if (L<Long>::test.invoke(L(1234L)) != 1234L) throw AssertionError()
if (S<String>::test.invoke(S("abcdef")) != "abcdef") throw AssertionError()
if (Z<Int>::test.let { it.invoke(Z(42)) } != 42) throw AssertionError()
if (L<Long>::test.let { it.invoke(L(1234L)) } != 1234L) throw AssertionError()
if (S<String>::test.let { it.invoke(S("abcdef")) } != "abcdef") throw AssertionError()
return "OK"
}
@@ -18,9 +18,9 @@ value class S(val x: String) {
}
fun box(): String {
if (Z::test.invoke(Z(42)) != 42) throw AssertionError()
if (L::test.invoke(L(1234L)) != 1234L) throw AssertionError()
if (S::test.invoke(S("abcdef")) != "abcdef") throw AssertionError()
if (Z::test.let { it.invoke(Z(42)) } != 42) throw AssertionError()
if (L::test.let { it.invoke(L(1234L)) } != 1234L) throw AssertionError()
if (S::test.let { it.invoke(S("abcdef")) } != "abcdef") throw AssertionError()
return "OK"
}
@@ -18,9 +18,9 @@ value class S<T: String>(val x: T) {
}
fun box(): String {
if (Z<Int>::test.invoke(Z(42)) != 42) throw AssertionError()
if (L<Long>::test.invoke(L(1234L)) != 1234L) throw AssertionError()
if (S<String>::test.invoke(S("abcdef")) != "abcdef") throw AssertionError()
if (Z<Int>::test.let { it.invoke(Z(42)) } != 42) throw AssertionError()
if (L<Long>::test.let { it.invoke(L(1234L)) } != 1234L) throw AssertionError()
if (S<String>::test.let { it.invoke(S("abcdef")) } != "abcdef") throw AssertionError()
return "OK"
}
@@ -14,7 +14,7 @@ fun box(): String {
val result1 = function1.invoke(Foo("+argument+"), 42)
if (result1.x != "original+argument+42") return "Fail first"
val result2 = Foo::bar.invoke(Foo("explicit"), Foo("+argument2+"), 10)
val result2 = Foo::bar.let { it.invoke(Foo("explicit"), Foo("+argument2+"), 10) }
if (result2.x != "explicit+argument2+10") return "Fail second"
return "OK"
@@ -14,7 +14,7 @@ fun box(): String {
val result1 = function1.invoke(Foo("+argument+"), 42)
if (result1.x != "original+argument+42") return "Fail first"
val result2 = Foo<String>::bar.invoke(Foo("explicit"), Foo("+argument2+"), 10)
val result2 = Foo<String>::bar.let { it.invoke(Foo("explicit"), Foo("+argument2+"), 10) }
if (result2.x != "explicit+argument2+10") return "Fail second"
return "OK"
@@ -4,7 +4,7 @@
OPTIONAL_JVM_INLINE_ANNOTATION
value class R(private val r: Long) {
fun test() = { ok() }()
fun test() = { ok() }.let { it() }
private fun ok() = "OK"
}
@@ -4,7 +4,7 @@
OPTIONAL_JVM_INLINE_ANNOTATION
value class R<T: Long>(private val r: T) {
fun test() = { ok() }()
fun test() = { ok() }.let { it() }
private fun ok() = "OK"
}
@@ -4,7 +4,7 @@
OPTIONAL_JVM_INLINE_ANNOTATION
value class R(private val r: Int) {
fun test() = { ok() }()
fun test() = { ok() }.let { it() }
fun ok() = "OK"
}
@@ -4,7 +4,7 @@
OPTIONAL_JVM_INLINE_ANNOTATION
value class R(private val r: Long) {
fun test() = { ok() }()
fun test() = { ok() }.let { it() }
fun ok() = "OK"
}
@@ -4,7 +4,7 @@
OPTIONAL_JVM_INLINE_ANNOTATION
value class R<T: Long>(private val r: T) {
fun test() = { ok() }()
fun test() = { ok() }.let { it() }
fun ok() = "OK"
}
@@ -4,7 +4,7 @@
OPTIONAL_JVM_INLINE_ANNOTATION
value class R<T: Int>(private val r: T) {
fun test() = { ok() }()
fun test() = { ok() }.let { it() }
fun ok() = "OK"
}
@@ -67,7 +67,7 @@ private fun testDelegateStr() {
localD = 1234
if (localD != 1234) throw AssertionError()
if (backing != 1234) throw AssertionError()
}()
}.let { it() }
}
private fun testDelegateInt() {
@@ -79,7 +79,7 @@ private fun testDelegateInt() {
localD = 1234
if (localD != 1234) throw AssertionError()
if (backing != 1234) throw AssertionError()
}()
}.let { it() }
}
private fun testDelegateLong() {
@@ -91,5 +91,5 @@ private fun testDelegateLong() {
localD = 1234
if (localD != 1234) throw AssertionError()
if (backing != 1234) throw AssertionError()
}()
}.let { it() }
}
@@ -67,7 +67,7 @@ private fun testDelegateStr() {
localD = 1234
if (localD != 1234) throw AssertionError()
if (backing != 1234) throw AssertionError()
}()
}.let { it() }
}
private fun testDelegateInt() {
@@ -79,7 +79,7 @@ private fun testDelegateInt() {
localD = 1234
if (localD != 1234) throw AssertionError()
if (backing != 1234) throw AssertionError()
}()
}.let { it() }
}
private fun testDelegateLong() {
@@ -91,5 +91,5 @@ private fun testDelegateLong() {
localD = 1234
if (localD != 1234) throw AssertionError()
if (backing != 1234) throw AssertionError()
}()
}.let { it() }
}
+8 -8
View File
@@ -18,16 +18,16 @@ fun box(): String {
if (MAX_LONG != ("" as String?) + Long.MAX_VALUE) return "fail \"\"? +"
if (MAX_LONG != "".plus(Long.MAX_VALUE)) return "fail \"\".plus"
if (MAX_LONG != ("" as String?).plus(Long.MAX_VALUE)) return "fail \"\"?.plus"
if (MAX_LONG != (String::plus)("", Long.MAX_VALUE)) return "fail String::plus"
if (MAX_LONG != (String::plus).let { it("", Long.MAX_VALUE) }) return "fail String::plus"
// if (MAX_LONG != stringPlus("", Long.MAX_VALUE)) return "fail stringPlus(\"\", Long.MAX_VALUE)"
// if (MAX_LONG != customToString("", Long.MAX_VALUE, String::plus)) return "fail customToString(\"\", Long.MAX_VALUE, String::plus)"
if (MAX_LONG != (String?::plus)("", Long.MAX_VALUE)) return "fail String?::plus"
if (MAX_LONG != (String?::plus).let { it("", Long.MAX_VALUE) }) return "fail String?::plus"
// if (MAX_LONG != stringNPlus("", Long.MAX_VALUE)) return "fail stringNPlus(\"\", Long.MAX_VALUE)"
// if (MAX_LONG != customToString("", Long.MAX_VALUE, String?::plus)) return "fail customToString(\"\", Long.MAX_VALUE, String?::plus)"
if (MAX_LONG != (""::plus)(Long.MAX_VALUE)) return "fail \"\"::plus"
if (MAX_LONG != (""::plus).let { it(Long.MAX_VALUE) }) return "fail \"\"::plus"
// if (MAX_LONG != emptyStringPlus(Long.MAX_VALUE)) return "fail emptyStringPlus(Long.MAX_VALUE)"
// if (MAX_LONG != customToString(Long.MAX_VALUE, ""::plus)) return "fail customToString(Long.MAX_VALUE, \"\"::plus)"
if (MAX_LONG != (("" as String?)::plus)(Long.MAX_VALUE)) return "fail \"\"?::plus"
if (MAX_LONG != (("" as String?)::plus).let { it(Long.MAX_VALUE) }) return "fail \"\"?::plus"
// if (MAX_LONG != emptyStringNPlus(Long.MAX_VALUE)) return "fail emptyStringPlus(Long.MAX_VALUE)"
// if (MAX_LONG != customToString(Long.MAX_VALUE, ("" as String?)::plus)) return "fail customToString(Long.MAX_VALUE, (\"\" as String?)::plus)"
@@ -36,16 +36,16 @@ fun box(): String {
if (PREFIX + MAX_LONG != (PREFIX as String?) + Long.MAX_VALUE) return "fail \"$PREFIX\"? +"
if (PREFIX + MAX_LONG != PREFIX.plus(Long.MAX_VALUE)) return "fail \"$PREFIX\".plus"
if (PREFIX + MAX_LONG != (PREFIX as String?).plus(Long.MAX_VALUE)) return "fail \"$PREFIX\"?.plus"
if (PREFIX + MAX_LONG != (String::plus)(PREFIX, Long.MAX_VALUE)) return "fail String::plus(\"$PREFIX\", ...)"
if (PREFIX + MAX_LONG != (String::plus).let { it(PREFIX, Long.MAX_VALUE) }) return "fail String::plus(\"$PREFIX\", ...)"
// if (PREFIX + MAX_LONG != stringPlus(PREFIX, Long.MAX_VALUE)) return "fail stringPlus(\"$PREFIX\", Long.MAX_VALUE)"
// if (PREFIX + MAX_LONG != customToString(PREFIX, Long.MAX_VALUE, String::plus)) return "fail customToString(\"$PREFIX\", Long.MAX_VALUE, String::plus)"
if (PREFIX + MAX_LONG != (String?::plus)(PREFIX, Long.MAX_VALUE)) return "fail String?::plus(\"$PREFIX\", ...)"
if (PREFIX + MAX_LONG != (String?::plus).let { it(PREFIX, Long.MAX_VALUE) }) return "fail String?::plus(\"$PREFIX\", ...)"
// if (PREFIX + MAX_LONG != stringNPlus(PREFIX, Long.MAX_VALUE)) return "fail stringNPlus(\"$PREFIX\", Long.MAX_VALUE)"
// if (PREFIX + MAX_LONG != customToString(PREFIX, Long.MAX_VALUE, String?::plus)) return "fail customToString(\"$PREFIX\", Long.MAX_VALUE, String?::plus)"
if (PREFIX + MAX_LONG != (PREFIX::plus)(Long.MAX_VALUE)) return "fail \"$PREFIX\"::plus"
if (PREFIX + MAX_LONG != (PREFIX::plus).let { it(Long.MAX_VALUE) }) return "fail \"$PREFIX\"::plus"
// if (PREFIX + MAX_LONG != prefixPlus(Long.MAX_VALUE)) return "fail prefixPlus(Long.MAX_VALUE)"
// if (PREFIX + MAX_LONG != customToString(Long.MAX_VALUE, PREFIX::plus)) return "fail customToString(Long.MAX_VALUE, \"$PREFIX\"::plus)"
if (PREFIX + MAX_LONG != ((PREFIX as String?)::plus)(Long.MAX_VALUE)) return "fail \"$PREFIX\"?::plus"
if (PREFIX + MAX_LONG != ((PREFIX as String?)::plus).let { it(Long.MAX_VALUE) }) return "fail \"$PREFIX\"?::plus"
// if (PREFIX + MAX_LONG != prefixNPlus(Long.MAX_VALUE)) return "fail prefixNPlus(Long.MAX_VALUE)"
// if (PREFIX + MAX_LONG != customToString(Long.MAX_VALUE, (PREFIX as String?)::plus)) return "fail customToString(Long.MAX_VALUE, \"$PREFIX\"?::plus)"
+1 -1
View File
@@ -24,7 +24,7 @@ interface Test {
return {
foo = "O"
foo + bar()
} ()
}.let { it() }
}
}
@@ -14,7 +14,7 @@ interface Test {
}
fun call(): String {
return { foo + bar()} ()
return { foo + bar() }.let { it() }
}
}
@@ -21,7 +21,7 @@ interface Test {
return {
foo = "O"
foo + bar()
} ()
}.let { it() }
}
}
@@ -12,7 +12,7 @@ interface Test {
get() = "K"
fun test(): String {
return (::foo)() + (::bar)()
return (::foo).let { it() } + (::bar).let { it() }
}
}
@@ -21,7 +21,7 @@ interface Test {
return {
foo = "O"
foo + bar()
} ()
}.let { it() }
}
}
@@ -10,7 +10,7 @@ open class A {
fun test(): String {
return {
publicField + internalField + protectedField
}()
}.let { it() }
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
fun foo() = "foo"
fun box(): String {
val f = (::foo)()
val f = (::foo).let { it() }
if (f != "foo") return "Fail: $f"
return "OK"
+6 -6
View File
@@ -9,27 +9,27 @@ object A {
@JvmStatic val c: String = "OK"
@JvmStatic fun test1() : String {
return {b}()
return {b}.let { it() }
}
@JvmStatic fun test2() : String {
return {test1()}()
return {test1()}.let { it() }
}
fun test3(): String {
return {"1".test5()}()
return {"1".test5()}.let { it() }
}
@JvmStatic fun test4(): String {
return {"1".test5()}()
return {"1".test5()}.let { it() }
}
@JvmStatic fun String.test5() : String {
return {this + b}()
return {this + b}.let { it() }
}
fun test6(): String {
return {c}()
return {c}.let { it() }
}
}
@@ -10,4 +10,4 @@ object O {
// FILE: u2.kt
fun box() = (O::foo)()
fun box() = (O::foo).let { it() }
+1 -1
View File
@@ -3,7 +3,7 @@
object Test {
fun test() = { createWildcard("OK") }()
fun test() = { createWildcard("OK") }.let { it() }
@JvmStatic
private fun createWildcard(s: String) = Type<Any>(s).x
@@ -2,7 +2,7 @@ val Int.getter: Int
get() {
return {
this@getter
}.invoke()
}.let { it.invoke() }
}
fun box(): String {

Some files were not shown because too many files have changed in this diff Show More