SpineEventEngine / Chords

UI components for Compose Multiplatform toolkit
Apache License 2.0
2 stars 0 forks source link

Codegen Runtime: see if `out` should be removed from `MessageField<T, out MessageFieldValue>` return values #38

Closed dpikhulya closed 1 month ago

dpikhulya commented 1 month ago

Here's an example of such a method in MessageOneof: https://github.com/SpineEventEngine/Chords/blob/3169ad3d96fc59ed4eaf41d973356d02d731254c/codegen/runtime/src/main/kotlin/io/spine/chords/runtime/MessageOneof.kt#L57

As I understand, having out here basically makes an instance of MessageField returned by this method read-only (by removing parts of its API that accept it as an input). If so, as far as I can see, having out in such returned MessageField values in this API and similar ones degrades its applicability since such fields cannot be modified without unchecked typecasting.

For this particular one I've stumbled onto a case where I needed to perform an unchecked cast like this to bring it back to a "writable" form: see here: https://github.com/SpineEventEngine/Chords/blob/f4c572a04298c839230449d61cea893e5c2fa0ed/proto/src/main/kotlin/io/spine/chords/proto/form/MessageForm.kt#L1289

So, preliminarily, I would consider having such out clauses near MessageFieldValue of MessageFields which are returned from our runtime codegen API to be worth removing. This is a fine topic though, so I believe we'd need to weigh and discuss this, and possibly see if this doesn't cause further issues, before accepting this as a final change.

dpikhulya commented 1 month ago

@Oleg-Melnik Sharing this thought, which might need to be discussed, so that I don't forget about this.