[Swift] extension with constraints cannot have inheritance clause

Originator:alex
Number:rdar://23255436 Date Originated:26-Oct-2015 11:36 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1 (7B91b)
Classification:Enhancement Reproducible:Always
 
Summary:
In some cases it would be useful to extend a generic type under some conditions for the generic argument. 

For example one could declare a protocol JSONEncodable to which all JSON types conform (e.g. Int, String, Bool, …). Each array of these types is JSON encodable as well and should also conform to JSONEncodable if it only contains elements that conform to JSONEncodable. However, writing an extension of Array like the following gives the error: Extension of type 'Array' with constraints cannot have an inheritance clause

extension Array: JSONDecodable where Element: JSONDecodable

Steps to Reproduce:
Open the sample project and try to compile it

Expected Results:
The code should compile and the array should conform to JSONEncodable if and only if its elements are JSONEncodable

Actual Results:
The code does not compile

Version:
Xcode 7.1 (7B91b)

Notes:


Configuration:


Attachments:
'SampleProject.zip' was successfully uploaded.
Sample project contains the following code:

protocol JSONEncodable {}

extension Int: JSONEncodable {}
extension String: JSONEncodable {}

extension Array: JSONEncodable where Element: JSONEncodable {
}

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!