[Pitch] - Take associated type inference one step further as compared to Swift 5.7

It would be so lovely if this code compiled:

struct SayHi: Procedure {
    var body: some Procedure<Void> {
        AtomicProcedure {
            print("Hi 🙋‍♂️")
        }
    }
}

struct AtomicProcedure <Output>: Procedure {
    var closure: ()->Output
    var body: Self { self }
}

protocol Procedure <Output> {
    
    var body: Body { get }
    
    associatedtype Body: Procedure
        where Body.Output == Self.Output
    
    associatedtype Output
}

alas... in Swift 5.7 I get the error:

Type 'SayHi' does not conform to protocol 'Procedure'

the problem is that the associated type Output of SayHi is not inferred to be Void despite me explicitly writing Void inside of the SayHi struct in a position which logically equates to that associated type (Output).

Of course, adding a simple:

typealias Output = Void

to the SayHi struct will allow the code to compile, so this use case which I find quite compelling is now perfectly possible today in Swift with the most recent and deal-changing thanks going to primary associated types.

Does this proposed type inference seem as obviously positive to you all as it does to me? And can anyone with deeper knowledge about what it would take to implement it chime in about the difficulty/blocking requirements?

Thanks!

4 Likes