Opaque Result types in Functions

I gave some code that looks like this:

protocol PAT {
    associatedtype R
}

protocol Foo {
    associatedtype Body: PAT
    
    func body<Bar: PAT>(for bar: Bar) -> Body
}

And I'm wondering why this doesn't work:

struct Baz: Foo {
    func body<Bar: PAT>(for bar: Bar) -> some PAT {
        
    }
}

This generates a compiler error: Baz doesn't conform to Foo.

Body != some PAT It can be anything, a concrete type or a protocol.

Terms of Service

Privacy Policy

Cookie Policy