yootsubo
(yootsubo)
1
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
SDGGiesbrecht
(Jeremy David Giesbrecht)
2
Bug...? I don’t think you’ve done anything wrong.
What does this do?:
let recast: Foo<Peach> = MegaFoo()
recast.whatAmI // ?
jrose
(Jordan Rose)
3
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
Panajev
(Goffredo Marocchi)
4
Do you reckon iOS 13 and Xcode 11 will go live with this bug then?
yootsubo
(yootsubo)
5
That is unfortunate.
Thanks for the quick response!