Re: [swift-users] Protocol extension gotcha... or bug?

2017-01-23 Thread Zhao Xin via swift-users
Wagner, the `extension` of `protocol` is never dynamic. It is `fail safe`. It means if you don't implement something, the compiler will use the implementation in the `protocol extension`. As in swift, struct and enum can also conform protocols. If you want the other way, you should do it in a base

Re: [swift-users] Protocol extension gotcha... or bug?

2017-01-23 Thread Wagner Truppel via swift-users
>> On 23 Jan 2017, at 19:56, Slava Pestov wrote: >> >>> class B: A { >>> var item: String { // subclass specialises 'item' by "overriding" the >>> protocol extension implementation >> >> This is the problem. You’re not overriding the protocol extension version, >> you’re just shadowing it for

Re: [swift-users] Protocol extension gotcha... or bug?

2017-01-23 Thread Slava Pestov via swift-users
> On Jan 23, 2017, at 7:31 AM, Wagner Truppel via swift-users > wrote: > > Say you have a protocol and an extension of it, like so: > > protocol P { > var item: String { get } > } > > extension P { > var item: String { > return "P" > } > } > > Now imagine a class that conforms to

[swift-users] Protocol extension gotcha... or bug?

2017-01-23 Thread Wagner Truppel via swift-users
Say you have a protocol and an extension of it, like so: protocol P { var item: String { get } } extension P { var item: String { return "P" } } Now imagine a class that conforms to that protocol and uses the property declared there but doesn’t specialise it in any way: class A