Swift: Arrays of protocols cannot be assigned to arrays of parent-protocols

Originator:wirth_caesar
Number:rdar://18483486 Date Originated:29-Sep-2014
Status:Duplicate of 18480439 (Open) Resolved:
Product:Swift Product Version:Version 6.1 (6A1030)
Classification: Reproducible:Always
 
Having an array of items of type `protocol MyProtocol`, and trying to assign to it an array of items of type `protocol ChildProtocol: MyProtocol` does not work. 
It works with classes and subclasses, but not protocols and child protocols.

See below for currently failing sample code.
Error displayed is ''ChildProtocol' is not identical to 'ParentProtocol''

protocol ParentProtocol {
    func name() -> String
}
 
protocol ChildProtocol: ParentProtocol {
    func age() -> Int
}
 
class Kid: ChildProtocol {
    func name() -> String {
        return "Kyle"
    }
 
    func age() -> Int {
        return 12
    }
}
 
func doThings() {
    var people: [ParentProtocol] = []
    var kids: [ChildProtocol] = [Kid(), Kid()]
    people = kids // error: 'ChildProtocol' is not identical to 'ParentProtocol'
}

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!