Allow top-level local delegated properties in scripts
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = 3
|
||||
}
|
||||
|
||||
|
||||
val prop: Int by Delegate()
|
||||
|
||||
val x = prop
|
||||
|
||||
// expected: x: 3
|
||||
@@ -8,7 +8,7 @@ class Delegate {
|
||||
}
|
||||
}
|
||||
|
||||
val a: Int <!SCRIPT_TOP_LEVEL_LOCAL_VARIABLE_WITH_DELEGATE!>by Delegate()<!>
|
||||
val a: Int by Delegate()
|
||||
|
||||
class Foo {
|
||||
val a: Int by Delegate()
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
>>> import kotlin.reflect.KProperty;
|
||||
>>> class Delegate {
|
||||
... var inner = 1
|
||||
... operator fun getValue(t: Any?, p: KProperty<*>): Int = inner
|
||||
... operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {
|
||||
... inner = i
|
||||
... }
|
||||
...}
|
||||
|
||||
>>> var prop1: Int = 1
|
||||
>>> prop1
|
||||
1
|
||||
>>> prop1 = 2
|
||||
>>> prop1
|
||||
2
|
||||
>>> var prop2: Int = 100
|
||||
>>> prop2
|
||||
100
|
||||
>>> prop2 = prop2 + 2
|
||||
>>> prop2
|
||||
102
|
||||
>>> prop1
|
||||
2
|
||||
Reference in New Issue
Block a user