Conditional Conformance with Protocol Inheritance

SR-6474 notwithstanding, I don't think this is a bug, although the error message certainly seems off-base.

Take a look at the implied conditional conformance section in the conditional conformance design doc, which is cited in SR-6474. It requires the "implied" conformances to be stated explicitly to forestall ambiguity of implementation. This topic is also being discussed in more detail in this thread.

It looks like Breathable and Movable don't actually need separate extensions. You can just name them in the same extension as for Leavable.

protocol Breathable {
    func breath()
}

protocol Movable {
    func move()
}

protocol Leavable: Breathable, Movable {}

struct Bee<Leaver> {
    let leaver: Leaver
}

extension Bee: Breathable, Movable, Leavable where Leaver: Leavable {
    func move() {
        leaver.move()
    }
    func breath() {
        leaver.breath()
    }
}

The code in the OP is missing an implementation of move() for Bee, so in fact it is not Leavable as shown. But I don't think the compiler ever got to that point. :slight_smile:

1 Like