Define a protocol type variable in another protocol
You can’t do this.
You define protocol p2
to conform to protocol p1
.
You define protocol p3
’s member del
to confirm to protocol p1
.
You define class c1
to conform to protocol p3
, and its member del
to conform to p2
.
Here’s the issue: if class c1
conforms to protocol p3
, then you should be able to assign anything that conforms to protocol p1
to its del
member. That’s what conforming to protocol p1
means, as you yourself have defined it.
But you have defined class c1
’s del
member to conform to protocol p2
. This is the problem.
This does work one way – anything conforming to protocol p2
is known to also conform to protocol p1
, so you can assign anything conforming to protocol p2
to an instance of class c1
’s member del
and it will be fine.
However it doesn’t work the other way. Things conforming to protocol p1
aren’t defined to conform to protocol p2
. So we have a gap. Because class c1
conforms to protocol p3
, you should be able to assign something that doesn’t conform to protocol p2
– but does conform to protocol p1
– to its member del
. That’s the way you’ve defined the protocol. But you’ve also defined c1
’s del
to conform to protocol p2
.
You’re telling the type system two different things. You’re saying that del
requires something that’s p1
indirectly through the protocol, and you’re saying that del
requires something that’s p2
directly through the class definition. Both can’t be true, so the compiler can’t proceed.