SE-0258: Property Wrappers (second review)

Here's the set of things I want to revise:

  • Give the private storage property a consistent name _<property name> regardless of whether wrapperValue is present. The leading underscore aligns with existing conventions. So the desugaring of @A public var foo: Int always has the basic form of:
private var _foo: A<Int>
public var foo: Int {
  get { _foo.wrappedValue }
  set { _foo.wrappedValue = newValue }
}
  • When wrapperValue is present, the $foo property becomes available and has the same access level as the original property foo, so when A has a wrapperValue (say it returns a Ref<Value>), the above example adds on:
public var $foo: Ref<Int> {
  get { _foo.wrapperValue }
  set { _foo.wrapperValue = newValue }
}
  • Rename wrapperValue to projectedValue, so that (1) it's not so close to wrappedValue and (2) gives us a specific term to use to talk about the $ property as the "projected property", a term that's been used a bit in the discourse here and describes the use cases well.

    Doug

EDIT: I dropped in the names I'm planning to use, which is based on subsequent feedback on this thread. A revised proposal + implementation is forthcoming.

17 Likes