"override" in protocols

protocols

(Daryle Walker) #1

[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?


(Adrian Zubarev) #2

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


(Dante Broggi) #3

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.


(Suyash Srijan) #4

Seems like it was added back in September in this PR: https://github.com/apple/swift/pull/19034