Files
kotlin-fork/compiler/testData/ir/irText/declarations/localDelegatedPropertyWithSuspendOperators.kt
T
Dmitry Petrov 6cefc0ddf3 Infer suspend flag for local delegated property accessors
Local delegated property accessors calling suspend operators getValue
or setValue should be suspend functions themselves.

KT-17605 Getter and setter of suspend delegated property are not suspend
2017-05-02 12:52:36 +03:00

27 lines
729 B
Kotlin
Vendored

// WITH_RUNTIME
import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED
import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn
import kotlin.reflect.KProperty
class A {
var z: Int = 42
operator suspend fun getValue(thisRef: Any?, property: KProperty<*>) = z
operator suspend fun setValue(thisRef: Any?, property: KProperty<*>, value: Int): Unit = suspendCoroutineOrReturn { x ->
z = value
x.resume(Unit)
COROUTINE_SUSPENDED
}
operator suspend fun provideDelegate(host: Any?, p: Any): A = suspendCoroutineOrReturn { x ->
x.resume(this)
COROUTINE_SUSPENDED
}
}
suspend fun test() {
val testVal by A()
var testVar by A()
}