Fix for KT-12891: Allow to omit type in local delegated property declaration

#KT-12891 Fixed
This commit is contained in:
Michael Bogdanov
2016-07-05 17:18:46 +03:00
parent 191dfa1f2b
commit 6b8e8cee17
7 changed files with 80 additions and 6 deletions
@@ -0,0 +1,5 @@
//WITH_RUNTIME
fun box(): String {
val x by lazy { "OK" }
return x
}
@@ -0,0 +1,12 @@
package foo
import kotlin.reflect.KProperty
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int = 1
}
fun box(): String {
val prop by Delegate()
return if (prop == 1) "OK" else "fail"
}
@@ -0,0 +1,19 @@
package foo
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
}
}
fun box(): String {
var prop by Delegate()
if (prop != 1) return "fail get"
prop = 2
if (prop != 2) return "fail set"
return "OK"
}
@@ -0,0 +1,14 @@
import kotlin.reflect.KProperty
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): Int = 3
}
fun foo(): Int {
val prop by Delegate()
return prop
}
val x = foo()
// expected: x: 3