Inline get/setValues for local delegated properties

This commit is contained in:
Mikhael Bogdanov
2016-06-14 13:03:14 +03:00
parent 6f761d4e7d
commit 679f53b449
12 changed files with 144 additions and 95 deletions
@@ -0,0 +1,12 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
inline operator fun getValue(t: Any?, p: KProperty<*>): String = p.name
}
fun box(): String {
val OK: String by Delegate()
return OK
}
@@ -0,0 +1,19 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
var inner = 1
inline operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
inline operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {
inner = i
}
}
fun box(): String {
var prop: Int by Delegate()
if (prop != 1) return "fail get"
prop = 2
if (prop != 2) return "fail set"
return "OK"
}