KT-12928: decompose invocation like "a.foo(b)" to "$t = a; $s = $t.foo.bind($t); $s(b)" instead of "$t = a.foo; $t(b)", since in the latter case foo won't receive proper this. Add optimization that replaces "foo.bar.bind(baz)(args)" with "baz.bar(args)"
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val v = mapOf(1 to "1", 2 to "2").mapValues { it.value.map { it.toString() } }
|
||||
assertEquals(2, v.size)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package lib
|
||||
|
||||
var global = ""
|
||||
|
||||
inline fun baz(x: () -> Int) = A(1).bar(x())
|
||||
|
||||
class A(val y: Int) {
|
||||
fun bar(x: Int) = x + y
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
import lib.*
|
||||
|
||||
fun qqq(): Int {
|
||||
global += "qqq;"
|
||||
return 23
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(24, baz {
|
||||
global += "before;"
|
||||
val result = qqq()
|
||||
global += "after;"
|
||||
result
|
||||
})
|
||||
assertEquals("before;qqq;after;", global)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package lib
|
||||
|
||||
var global = ""
|
||||
|
||||
inline fun baz(x: () -> Int) = ((A(1).B(x()) as Any) as A.B).bar()
|
||||
|
||||
class A(val y: Int) {
|
||||
inner class B(val x: Int) {
|
||||
fun bar() = x + y
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
import lib.*
|
||||
|
||||
fun qqq(): Int {
|
||||
global += "qqq;"
|
||||
return 23
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(24, baz {
|
||||
global += "before;"
|
||||
val result = qqq()
|
||||
global += "after;"
|
||||
result
|
||||
})
|
||||
assertEquals("before;qqq;after;", global)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user