public protocol BidirectionalCollection: Collection
where SubSequence: BidirectionalCollection, Indices: BidirectionalCollection {
// FIXME: Only needed for associated type inference.
override associatedtype Element
override associatedtype Index
override associatedtype SubSequence
override associatedtype Indices
...
override func index(after i: Index) -> Index
//^^^^^^^^ `override` in protocol...?
...
My understanding was that override is explicitly for reference types and it was first time to see it in the other area.
I couldn't find any mention of it in The Swift Programming Language (Swift 5.6) neither.
The override keyword, when used with protocols, is an internal undocumented feature implemented for ABI-related reasons (namely, to drop the overriding member from witness tables) that has never gone through Swift Evolution:
override on associated-type declarations has (or at least had, not sure of the current situation) some effect on type inference. I can’t remember the details, but in some situations omitting the override keyword would cause type inference to fail.
Well, my initial thought was, in case if it was for internal use (which is now I know it is), it's a bit scary because it's not underscored, normal reserved keyword you would often see if you work with Obj-C modules which is apparently not a rare-case.
Although at the same time I think there will be (almost) no case that one uses it accidentally, causing an unintended behavior... I did not happen to even think to type override in protocol until today.
It does not directly affect associated type inference. The bug with associated type inference is that associated types must be re-stated in an inherited protocol for inference to work. We didn't want such associated types to be part of the ABI, since we'd like to fix the bug and remove them at some point, so we implemented override checking for protocol requirements.
The standard library is built with a special frontend flag (-warn-protocol-override) where a missing override keyword on a re-stated protocol requirement is a warning. Normally this is not diagnosed since users don't generally care if a protocol requirement is re-stated or not.