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

Dale Buckley dalebuckley86 at gmail.com
Mon Mar 13 12:29:35 CDT 2017


Hi All,

This is an inconsistency I've come across a few times now so I thought I
would detail exactly what the inconsistency is and how I think it should
work. This is a bug thats been reported on JIRA, but when commenting on the
issue Doug Gregor pointed out that this should be a proposal rather than a
bug report.

Simply put (or as simply as I can), when inheriting from a class that
conforms to a protocol that has a protocol extension, not all methods
defined in that protocol are implemented by the class as it relies on the
protocol extension implementations. This is fine until that class is
subclassed tries to add it's own implementation of the methods defined in
the protocol even if they aren't implemented in it's parent class. Once
this situation arrises some problems happen if the parent class calls any
of the methods defined in the protocol but not implemented by itself, but
by it's subclass. If the methods are called externally then everything is
fine, but if the methods are called internally by the parent class, the
subclasses implementations are ignored and the protocol extension
implementation is used instead.

It's a long winded problem to describe which is why I have added a code
sample to my draft proposal to help illustrate the problem better. If
anyone has any tips on how to simplify the description of the problem then
I'm all ears!

https://gist.github.com/dlbuckley/1858a7c0b5c027248fe16171d23ba01d

I believe that this proposal should bring a more consistent and expected
behaviour to code when this situation arrises. Let me know if you believe
the same or disagree.

Thanks,

Dale
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170313/1501005d/attachment.html>


More information about the swift-evolution mailing list