Why is it not possible to constraint associatedtype with a protocol inheritance?

Viewed 39

I know that in a situation where a protocol is used with associated value it is usually required to do type erasure. But sometimes it seems overkill. For example the situation where we know that some of classes will have associated type set to Any we could make a protocol which makes the constraint with where clause. Like in the following example:

protocol A {
    associatedtype B
    
    func a(b: B)
}

protocol C: A where B == Any {}

func runC(_ c: C) { // Protocol 'C' can only be used as a generic constraint because it has Self or associated type requirements
    c.a(b: Data())
}

class CImpl: C {
    func a(b: B) {
        print(b)
    }
}

runC(CImpl())

Why does it still complains about constraints on the func runC when it has one in protocol C? Is there a way to make it work without type erasure boilerplate?

0 Answers
Related