Why are local property references not allowed, whe...
# language-evolution
y
Why are local property references not allowed, when local delegated properties are a thing, AND they receive a property instance in their
getValue
and
setValue
methods? Is it to do with how regular local properties have a weird "backing field" and so supporting that can get muddy when it comes to cross-thread references and all? or is there another piece to the puzzle? And if that's the case, why not allow references to local delegated properties? After all, their mechanics are near-identical to normal delegated properties.
u
Basically because it’s unclear how to implement `get`/`set` for such property references on JVM. The KProperty instance for local delegated property which is passed to `getValue`/`setValue` explicitly throws exception on `get`/`set`. Maybe we should just accept this behavior and allow such references though, since they’re still useful at least to introspect name & type.
e
wouldn't it be possible to make `get`/`set` work by wrapping locals with
Ref.ObjectRef<>
? there is some cost to this of course…
y
I would agree with @ephemient . I think the behaviour should be the same as variables captured in closures. In other words, a property reference
::localVariable
should have accessors similar to these lambdas:
Copy code
KProperty(get = { localVariable }, set = { localVariable = it })