[swift-evolution] [Draft Proposal] Improve protocol inheritance behaviour

Dale Buckley dalebuckley86 at gmail.com
Tue Mar 14 06:55:57 CDT 2017

So having a little more of a think about this what should happen in this

class A {
    func method() {

protocol P {
    func method()

extension P {
    func method() {

class B: A, P {
    override func method() {


When 'super' is called by the method in class B, should it call the method
in class A or the protocol extension in extension P? As it stands by using
override it always looks to it's superclass and ignores what happens in the
protocol extension. This says to me that the 'override' keyword isn't right
for solving this issue and should be reserved for inheritance, and not for
solving this issue with choosing the subclass implementation over the
protocol extension implementation.


On Tue, Mar 14, 2017 at 11:39 AM, Dale Buckley <dalebuckley86 at gmail.com>

> So I did consider using the 'override' keyword, but it then raised the
> question as to what should happen when 'super' is called.
> I agree that by adding 'override' it makes it more obvious that you are
> overriding an existing implementation of the method, regardless of if it's
> defined in the class you are inheriting from or from the protocol
> extension. But if you add 'override' you are explicitly saying you can call
> the super implementation.
> So the question is what should happen here? Realistically you could expect
> calling 'super' would call the protocol extension implementation of the
> method, but I'm trying to think of the problems that could occur if its
> implemented in that way.
> Any thoughts on this?
> Dale
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170314/7b0c09dc/attachment.html>

More information about the swift-evolution mailing list