How to refer to a subscript getter

It's never been possible.

Same situation for callAsFunction.

The closest the language allows to what you need is to supply an argument, effectively turning a subscript into a property. In the case of a () -> subscript, this syntax is just empty brackets.

struct S {
  subscript() -> Void {
    get { () }
    nonmutating set { }
  }
}


\S.[] // ReferenceWritableKeyPath<S, ()>
[S()].map(\.[])
S()[keyPath: \.[]] = ()

No similar feature exists for callAsFunction. Having both () and [] in this language is an anachronism.

1 Like