Swift : Resolve parent protocol associated type requirements in inheriting protocols
| Originator: | amber | ||
| Number: | rdar://23429290 | Date Originated: | 06-Nov-2015 07:54 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Swift 2.1 |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
If protocol A has associated type requirements it can not be used in a heterogeneous collection.
protocol ProtocolA {
typealias : Element
}
var n : [ProtocolA] // Protocol `ProtocolA` can only be used as a generic constraint because it has Self of associated type requirements
Allow the type requirement to be resolved in an inheriting protocol:
protocol ProtocolB : ProtocolA {
Element = ConcreteType
}
var n : [ProtocolB] // okay to use ProtocolB in a heterogeneous collection.
I am using the heterogeneous collection as one example, but it allows ProtocolB to be used as a type (without generics). This would be very useful in many situations.
If we can provide default implementations for method and property requirements in extensions, why can’t we also provide type reference requirements?
Notes:
Please see attached markup.
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!