Constrained associated type on protocol

Why associated type requirement persists when a constrain is defined on a protocol?
For instance:

protocol P1 {
    var id: String { get }
var p1Array: [P1]  // OK

protocol P2: Identifiable where Self.ID == String {
var p2Array: [P2]  // Protocol 'P2' can only be used as a generic constraint because it has Self or associated type requirements

Thank you

P2 has no associated types of its own, but it inherits from Identifiable, which does. (ID is the associated type.)

Thank you but I know that and this is not my question.

IMHO when a constrain is defined by equality like here, the associated type should be requalified as a typealias and therefore [P2] declaration accepted.

I should not create a AnyP2 type eraser since in scope of P2, all types are resolved: ID can't be anything else than a String.

Ah, I see what you are getting at: Why doesn’t the compiler check whether the constraints narrow it to a single type? I don’t know if there is a technical reason or if it is just an oversight. Someone more familiar with the compiler implementation will have to answer.

1 Like

Thank you for you replies.