I have a property delegate using a context receiver:
class LoggingPropertyDelegate<T, V, L : Log>(
private var value: V,
private val toLog: T.() -> L
) : ReadWriteProperty<T, V> {
override fun getValue(thisRef: T, property: KProperty<*>) = value
context(Logger)
override fun setValue(thisRef: T, property: KProperty<*>, value: V) {
this.value = value
log(toLog(thisRef))
}
}
But when I try to use it on a property:
var myValue: Int by LoggingPropertyDelegate(0, { InfoLog("Changed to $myValue") })
I get an error that there is no suitable set
functions for the delegate. If I remove the context from the method everything works as expected.
Is it not possible to use context receivers on property delegates?