Proposal: side-effect free getters It's a pretty ...
# language-proposals
j
Proposal: side-effect free getters It's a pretty well-known problem that if you split a project into multiple modules, you lose some smart casting because the compiler cannot assume that a getter in another module will always return the same result. I'd like to propose adding an annotation that indicates that the library author intends for a getter to remain side-effect free so that clients can write code more naturally. Thoughts?
👍 4
👍🏻 1
I mean it returns the same value every time unless you call something else on the object (e.g. a setter)
This would be an annotation on the property.
It would be useful for custom getters too!
Not at all! Useful clarification.
r
I think this would be an excellent feature, but IMO it should be done using contracts rather than a bespoke annotation
j
But how would one attach a contract to a generated getter?
j
Not sure if that covers everything, but it's definitely a starting point!
Am curious if anyone has ideas on how one could attach a contract to a generated function (i.e. a function that doesn't have a body in the code)
e
I don't think this would be handled by a contract anyway, at least in the current design. they feel very per-call
if that were how it works, then you can just contract the getter like how you can annotate the getter now
‼️ 1