Swift 2.0: Protocol Extensions Enable Invalid Overloading/Shadowing of Properties in Implementations

Originator:wetzeal
Number:rdar://22908664 Date Originated:29-Sep-2015 08:11 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.0 (7A220)
Classification:Serious Bug Reproducible:Always
 
Summary:
A type which implements a protocol can define a property with the same name as in a protocol but with different type if the property is defined in a protocol extension. The runtime will continue to use the protocol extension implementation, even if the implemented type is covariant with the protocol type, e.g. if the protocol defines an optional type but the implementation uses a non-optional type. This looks like it’s behaving like a type override, but the overridden version is inaccessible.

Expected Results:
I expect either:
A) The compiler raises an exception that the property name conflicts with the protocol when the type does not match.
B) In valid covariant cases, the type’s implementation is used rather than the protocol extension’s.

Actual Results:
The code compiles with no warnings, but accessing the conflicting property always uses the protocol extension implementation.

Notes:
The attached playground shows this happening. If the property’s type is explicitly defined to match the protocol’s, the problem goes away as the property is correctly implemented. This happens in both Xcode 7.0 and 7.1b2

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!