Xcode-beta (7A121l): Typealias for generic functions within a protocol do not work

Originator:owensd
Number:rdar://21571050 Date Originated:26-Jun-2015 01:52 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A121l)
Classification:Other Bug Reproducible:Always
 
A protocol that attempts to define a typealias that is a function using the protocol type constraints does not work.

protocol Emotional {
    typealias Sad
    typealias Happy
    
    typealias F = (state: Sad) -> Happy
    typealias G = (state: Int) -> Int
    typealias H = (hi: Sad, bye: Happy)
    
    var funcs: [F] { get }
    var emotes: [G] { get }
    var faces: [H] { get }
}

And the conforming type:

struct Emote : Emotional {
    let funcs: [(state: Int) -> Int] = [{ $0 }]
    let emotes: [(state: Int) -> Int] = [{ $0 }]
    let faces: [(hi: Int, bye: Int)] = [(hi: 0, bye: 1)]
}

let e = Emote()
e.funcs[0](state: 1)     // 1
e.emotes[0](state: 12)   // 12
e.faces[0]               // (.0 0, .1 1)

This won’t compile; Emote does not conform to Emotional.

However, changing the protocol to this is fine:

protocol Emotional {
    typealias Sad
    typealias Happy
    
    typealias G = (state: Int) -> Int
    typealias H = (hi: Sad, bye: Happy)
    
    var funcs: [(state: Sad) -> Happy] { get }
    var emotes: [G] { get }
    var faces: [H] { get }
}

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!