Support local 'toDelegatedFor' properties

This commit is contained in:
Mikhael Bogdanov
2016-12-08 17:14:19 +01:00
committed by Stanislav Erokhin
parent c5e14a2059
commit 937a933150
11 changed files with 253 additions and 4 deletions
@@ -0,0 +1,26 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JS
import kotlin.test.*
var log: String = ""
inline fun <T> runLogged(entry: String, action: () -> T): T {
log += entry
return action()
}
operator fun String.toDelegateFor(host: Any?, p: Any): String =
runLogged("tdf($this);") { this }
operator fun String.getValue(receiver: Any?, p: Any): String =
runLogged("get($this);") { this }
fun box(): String {
val testO by runLogged("O;") { "O" }
val testK by runLogged("K;") { "K" }
val testOK = runLogged("OK;") { testO + testK }
assertEquals("O;tdf(O);K;tdf(K);OK;get(O);get(K);", log)
return testOK
}
@@ -0,0 +1,26 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JS
import kotlin.test.*
var log: String = ""
fun <T> runLogged(entry: String, action: () -> T): T {
log += entry
return action()
}
operator fun String.toDelegateFor(host: Any?, p: Any): String =
runLogged("tdf($this);") { this }
operator fun String.getValue(receiver: Any?, p: Any): String =
runLogged("get($this);") { this }
fun box(): String {
val testO by runLogged("O;") { "O" }
val testK by runLogged("K;") { "K" }
val testOK = runLogged("OK;") { testO + testK }
assertEquals("O;tdf(O);K;tdf(K);OK;get(O);get(K);", log)
return testOK
}
@@ -0,0 +1,34 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JS
import kotlin.test.*
var log: String = ""
class MyClass(val value: String)
fun runLogged(entry: String, action: () -> String): String {
log += entry
return action()
}
fun runLogged2(entry: String, action: () -> MyClass): MyClass {
log += entry
return action()
}
operator fun MyClass.toDelegateFor(host: Any?, p: Any): String =
runLogged("tdf(${this.value});") { this.value }
operator fun String.getValue(receiver: Any?, p: Any): String =
runLogged("get($this);") { this }
fun box(): String {
val testO by runLogged2("O;") { MyClass("O") }
val testK by runLogged("K;") { "K" }
val testOK = runLogged("OK;") { testO + testK }
assertEquals("O;tdf(O);K;OK;get(O);get(K);", log)
return testOK
}