[Discussion] Inclusion of CasePaths into the language

Subscripts are not currently capable of doing what a case path (or even a writable optional-chained path) needs to do because the type returned from the getter is different from the type sent to the setter:

  • The getter is optional
  • The setter is non-optional

This behavior would either need to be special cased by the compiler, or subscript/property syntax would need to change to support this. Pseudosyntax:

subscript<Value>(
  casePath: CasePath<Self, Value>
) -> Value? {
  get { … }
  nonoptional set { … }
}

I’d rather not get into design details, though, without a means of implementing. But if a person familiar with the compiler is interested in working on an implementation, I’d be more than happy to help with the design.

6 Likes