Xcode 7.1b (7B60): [Swift] Allow constrained protocol extensions to implement protocol conformances

Originator:janoschhildebrand
Number:rdar://22819751 Date Originated:23-Sep-2015
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1b1
Classification:Enhancement Reproducible:n/a
 
Summary:
It would be nice if it were possible to add protocol conformances in constrained protocol extensions, that is to add protocol conformances only to a subset of a generic type or type with an associated type.


For example, look at the section 'Adding Constraints to Protocol Extensions' in the 'Protocols' chapter of 'The Swift Programming Language'.

Therein, 'CollectionType' is extended to provide the 'textualDescription' property in case the CollectionType's elements conform to the 'TextRepresentable' protocol.

'textualDescription' itself is part of the 'TextRepresentable' protocol and the element's conformance is used to build the collection's description. However, 'CollectionType' itself cannot currently be conformed to 'TextRepresentable' using the constrained extension as presented in that section of the guide.


Another example of where this might be useful would be to extend 'CollectionType' with 'Equatable' conformance in case the collection's elements conform to equatable themselves.


The syntax for this could look like this for example:

extension CollectionType : Equatable where Generator.Element : Equatable { }

Swift can already detect the users intention and currently emits an error message to inform that this is not (yet) possible:

'Extension of protocol 'CollectionType' cannot have an inheritance clause.'

Steps to Reproduce:


Expected Results:


Actual Results:


Version:
OS X 10.11 (15A282b)
Version 7.1 beta (7B60)
Apple Swift version 2.0 (swiftlang_PONDEROSA-700.1.100.2 clang-700.1.74)

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!