Hi,
I have the following code example. In my real case the protocol P has additional properties that I want to enforce to protocols A and B, but this does not make a difference to explain the issue I have.
protocol P : Codable { }
protocol A : P {
var prop : B? { get }
}
protocol B : P {
var prop : String? { get }
}
class BB : B {
var prop: String? = nil
}
class AA : A {
var prop: B? = nil
}
Compiling it results in errors:
Error:(, ) type 'AA' does not conform to protocol 'Decodable'
Error:(, ) type 'AA' does not conform to protocol 'Encodable'
I was expecting the hierarchy of protocols and classes here to all support codable, as protocol P is Codable, and protocols A and B both inherits from protocol P. And as a result, I expected the compiler to synthesize the requirements for the Codable typealias for classes AA and BB.
If I change the protocol A definition to require a property of type String instead of B? then it works.
I know that the codable synthesis requires all the properties of the class to be codable, but I can't help but think that they all are...
Why does the compiler not synthesize in my example? Why is it unreasonable to expect it to?