Conditional Conformance and Inheritance

Hello,

I'm trying to use conditional conformance on a generic object, it works but when I inherit from the generic class, it seems to be losing the conditional conformance.

Any idea what I might be doing wrong here?

protocol Tasty { }
protocol Juicy { }

struct Peach: Tasty, Juicy { }

protocol Juiceable { }

class Foo<C> where C: Tasty {

    var whatAmI: String {
        if self is Juiceable {
            return "Is Juiceable"
        } else {
            return "Not Juiceable"
        }
    }
}

extension Foo: Juiceable where C: Juicy { }

class MegaFoo: Foo<Peach> { }

let megaFoo = MegaFoo()
megaFoo.whatAmI // Not Juiceable

let foo = Foo<Peach>()
foo.whatAmI // Juiceable
1 Like

Bug...? I don’t think you’ve done anything wrong.

What does this do?:

let recast: Foo<Peach> = MegaFoo()
recast.whatAmI // ?

Yeah, I can reproduce this in the Xcode 11 beta, but not on master, so I think it's a bug that's been fixed (but probably won't make it into an Xcode for a while, sorry).

3 Likes

Do you reckon iOS 13 and Xcode 11 will go live with this bug then?

That is unfortunate.

Thanks for the quick response!