More wise lambda search during inlining

This commit is contained in:
Michael Bogdanov
2016-02-03 13:49:20 +03:00
parent 16f412f993
commit bc2077bfaf
16 changed files with 269 additions and 4 deletions
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return ContentTypeByExtension.processRecords { ext -> ext }
}
@@ -0,0 +1,18 @@
package test
object ContentTypeByExtension {
inline fun processRecords(crossinline operation: (String) -> String) =
listOf("O", "K").map {
val ext = B(it)
operation(ext.toLowerCase())
}.joinToString("")
}
inline fun A.toLowerCase(): String = (this as B).value
open class A
open class B(val value: String) : A()
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return ContentTypeByExtension.processRecords { ext -> ext }
}
@@ -0,0 +1,18 @@
package test
object ContentTypeByExtension {
inline fun processRecords(crossinline operation: (String) -> String) =
{
val ext = B("OK")
operation(ext.toLowerCase())
}()
}
inline fun A.toLowerCase(): String = (this as B).value
open class A
open class B(val value: String) : A()
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return processRecords { ext -> ext + "K" }
}
@@ -0,0 +1,5 @@
package test
inline fun foo(x: String) = x
inline fun processRecords(block: (String) -> String) = block(foo("O"))
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return processRecords { "O" + it }
}
@@ -0,0 +1,11 @@
package test
inline fun foo(x: String) = x
class A {
fun test(s: String) = s
}
inline fun processRecords(block: (String) -> String): String {
return A().test(block(foo("K")))
}
@@ -0,0 +1,7 @@
import test.*
fun box(): String {
val result = processRecords { "B" + it }
return if (result == "BOK1") "OK" else "fail: $result"
}
@@ -0,0 +1,11 @@
package test
inline fun foo(x: String, y: String) = x + y
class A {
fun test(s: String) = s
}
inline fun processRecords(block: (String) -> String): String {
return A().test(block(foo("O", foo("K", "1"))))
}
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return processRecords { a, b -> a + b}
}
@@ -0,0 +1,10 @@
package test
inline fun foo(x: String) = x
fun test(a: String, s: String) = s
inline fun processRecords(block: (String, String) -> String): String {
return test("stub", block(foo("O"), foo("K")))
}