[swift-evolution] Static Dispatch Pitfalls
Vladimir.S
svabox at gmail.com
Mon May 23 16:39:31 CDT 2016
On 23.05.2016 23:09, Xiaodi Wu via swift-evolution wrote:
> One option, which I think is entirely valid, is to decide that extensions
> on a protocol are not to be shadowed by a conforming type.
Just to have the whole picture for those, who is reading your discussion
with Matthew : yes, extensions(that were not declared in protocol itself)
are not shadowed by a conforming type(if called by reference which type is
protocol, i.e let p = MyProtocol = MyType()). And I agree, that when you
know this - this is a simple rule.
But, you have to remember another rules:
* default implementation of protocol requirement (in protocol extension) -
*will* be shadowed by type's method *if* implemented *exactly* in the same
type that conformed to protocol
* default implementation of protocol requirement (in protocol extension) -
will *not* be shadowed *if* implemented in derived type which base type
conformed to protocol (i.e. type has implemented the method, type is
conformed to protocol, but protocol's default implementation will be called)
For me (now), it seems like these rules has strong reasons and we will not
change them. OK. But IMO we definitely needs some help from Swift to avoid
possible *not easy to fix* errors related to these rules.
More information about the swift-evolution
mailing list