Xcode-7-beta.5 (7A176x): [Swift] Add automatic type-erasure to protocols
| Originator: | segiddins | ||
| Number: | rdar://22176770 | Date Originated: | 06-Aug-2015 01:43 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-7-beta.5 (7A176x) |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
Protocols in swift are awesome. Even more awesome is when we can use them directly as properties, which is currently impossible when the protocol has self/associated type requirements.
Steps to Reproduce:
struct TableViewController {
var items: CollectionType<T>
// error: cannot specialize non-generic type 'CollectionType'
// error: protocol 'CollectionType' can only be used as a generic constraint because it has Self or associated type requirements
}
Expected Results:
Should compile.
Actual Results:
But totally doesn’t.
Notes:
Look at all the boilerplate necessary to generate type-erased wrapped for protocol types: https://realm.io/news/type-erased-wrappers-in-swift/. The compiler totally knows all that info, and could do it for us. Making protocol-oriented programming in Swift even more practical.
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!