Swift 2: Allow protocol extension to adopt a Protocol (aka recursive protocol adoption)

Originator:gwendal.roue
Number:rdar://21335418 Date Originated:11-Jun-2015
Status:Open Resolved:
Product:Developes tools Product Version:Xcode Version 7.0 beta (7A120f)
Classification: Reproducible:Always
 
Summary:
It looks like protocol extensions can't declare a conformance to a protocol. The following code seems to compile, but Swift Playground won't display any value, showing that it can run:

    protocol P { }
    extension CollectionType: P { }
    let p = [1] as! P

That would be nice, because it would allow protocol adoption to recursively cascade from simple types to collections and dictionaries of those types:

    protocol P { }
    extension CollectionType : P where Generator.Element : P { }
    extension DictionaryLiteralConvertible : P where Key : String, Value : P { }
    extension Int: P { }

    let a: P = 1
    let b: P = [1, 2, 3]
    let c: P = [[1, 2], [3, 4]]
    let d: P = ["foo": [[1, 2], [3, 4]]]
    let e: P = [["foo": 1], ["bar": 2]]

Steps to Reproduce:
See Description

Expected Results:
No compilation error, and the recursive adoption of a protocol.

Actual Results:
No recursive protocol adoption

Version:
Xcode Version 7.0 beta (7A120f)

Notes:
Please :-)

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!