[swift-users] A confusing protocol extension behaviour/bug

Marc Palmer marc at anyware.co.uk
Tue Jan 2 02:42:06 CST 2018


> On 1 Jan 2018, at 20:40, Toni Suter <tonisuter at me.com> wrote:
> 
> Hi Marc,
> 
> There are several subtleties here, but I think the compiler is actually doing the right thing.
> 

Hi Toni,

Thanks for your detailed response. 

[..]
> The second class defines a static property that looks like it is 'overriding' the static property from
> the protocol extension, but since the types don't match (String vs. String?), it sort of 'overloads'
> the property (similar to function overloading). Nevertheless, the class still fulfills the requirements
> of the Trackable protocol, by inheriting the static property from the protocol extension.

Isn’t this a compiler bug?

I didn’t realise that overloading properties was a thing? I’m pretty sure it isn’t, in which case the compiler should choke because there are two properties of the same name but divergent types available on the type. 

This behaviour seems to create major hard-to-detect hazards when using protocol extensions, which seems against the spirit of Swift. 

Marc


More information about the swift-users mailing list