[swift-evolution] [Proposal] Property behaviors

Chris Lattner clattner at apple.com
Wed Jan 20 17:15:12 CST 2016

> On Jan 20, 2016, at 9:48 AM, Matthew Johnson <musical.matthew at mac.com> wrote:
>>> One thought is that it might be good to allow behaviors to have `init` accessor that is used if the property is assigned by an initializer of the containing type (only the first time the property is assigned).  This would clarify what happens during initialization of the containing type and allow for different init and set code paths when necessary.   It would be distinguished from the behavior initializer by the lack of parens.  If that is too subtle we could use a different name for the initialization accessor.
>> That's a possibility, but inserting initializer calls is a bit more heroic than what our current definite initialization implementation can do. That's not necessarily a showstopper, but it was a goal of the current design to avoid inserting accessor calls within inits at hard-to-predict places. (cc'ing ChrisL, to get his opinion on this as DI owner)
> Makes sense.  Getting the behavior I would like to see out of a `phase2Immutable` behavior would definitely require updates to the DI rules.  I think the added safety makes it worth doing something in this area eventually, but it could be added later.  I’m interested to hear what Chris thinks.

Swift’s semantics have a big (but largely invisible/unknown to developers) divide between initialization and reassignment.  I agree that it makes sense to expose this different out of a behavior because they may want to do something interesting.

That said, the divide shouldn’t be “assigned in an containing initializer” vs “assigned to somewhere else”. You should be able to have a behavior on a local variable for example.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160120/b3f9d460/attachment.html>

More information about the swift-evolution mailing list