"override" in protocols

[Maybe this should be in "Using Swift".]

I was reading the implementation of "RangeReplaceableCollection.swift" and noticed that there were three items from Collection repeated in the RangeReplaceableCollection primary definition. Those items had the "override" specifier added. Is that new for Swift 5? What does it mean?

Those three repeats (SubSequence, subscript(bounds: Index), and subscript(bounds: Range<Index>)) had a "FIXME: Associated type inference requires these." comment attached. Does that mean the override specifier for protocols will go away once the fix is in?

2 Likes

Can you provide links to the lines in code please, I‘m curious what exactly you discovered?!

Having been lurking PRs when this was being implemented, I recall that protocol overrides were added as a (stdlib private) feature to permit protocols to redeclare requirements, e.g. for associated type inference, while preventing the declaration from adding to the protocol's ABI.

2 Likes

Seems like it was added back in September in this PR: Introduce overrides of protocol members and drop them from witness tables by DougGregor · Pull Request #19034 · apple/swift · GitHub