When is `any` mandatory when creating a variable conforming to a protocol

That was the original plan, but the decision was later reverted. The any P syntax will not be required for existentials in the Swift 6 language mode.

Holly Borla, Progress toward the Swift 6 language mode (2023-11-07):

The Language Steering Group has decided that one previously-accepted upcoming feature, ExistentialAny, will not be enabled by default in Swift 6. SE-0335: Introduce existential any introduces the any keyword to identify existential types. The proposal also specifies that "bare" protocol names will no longer be permitted as types---they must either use any or some, as appropriate---under the upcoming feature flag ExistentialAny. Given the concerns about migration to consistent use of existential any in the language, and the expectation that additional language improvements will be coming that might affect the end result of that migration, the Language Steering Group is deferring the source-incompatible changes in SE-0335 to a future language revision.

I would still suggest getting into the habit of writing any P everywhere because it's the better syntax IMO:

  • One consistent spelling for all existentials
  • Using different spellings for when a protocol is used as a constraint (no any) vs. when it's used as an existential is a good thing
  • Nice congruence between the any P and some P spellings, which can be used in similar places (though note that there have been discussions to make the plain P spelling actually mean some P in a future language version because some P should generally be preferred unless you explicitly need any P)
6 Likes