Satisfying protocol requirement with specific type

A protocol without Self or associated type requirements can be used as a concrete type; that type is called a "protocol type" in some places in Swift, but is otherwise known as an "existential type." There is a ton to know about these types, but I will quote the following paragraph by way of background:

In the future, it would be possible for Child to conform to itself because there are no Self or associated type requirements. But even in that future, B (a concrete type) would not have a subtyping relationship with Child (another concrete type) any more than it would with another hypothetical class C that conforms to Child.

Your protocol Parent demands a function that returns a value of concrete type Child. Returning a value of type B does not and will never satisfy that requirement. To create a contract for a function that "returns something that conforms to the Child protocol," use an associated type constraint in your protocol.

2 Likes