Adding a setter is purely additive—like going from KeyPath
to WritableKeyPath
. It doesn't require the mental gymnastics that everything else that compiles in this thread does. You also can't derive "in the wrong direction".
protocol GetSet {
var property: Void { get set }
}
protocol Get: GetSet {
var property: Void { get } // Cannot override mutable property with read-only property 'property'
}
After thinking more about this, and looking into the failure of Rethrowing protocol conformances, I wouldn't know what issue to bring up—I feel pretty disheartened about the inconsistencies, and lack of ability to represent truth. But while I can't bring myself to see e.g. nonmutating
being a subtype of mutating
, I can at least see how it's the same as being able to shadow a member at various levels of a protocol hierarchy.
protocol GetVoid {
var property: Void { get }
}
protocol GetBool: GetVoid {
var property: Bool { get }
}
protocol GetInt: GetBool {
var property: Int { get }
}
protocol GetString: GetInt {
var property: String { get }
}
extension GetString {
var properties: (Void, Bool, Int, String) {
let selfs: (some GetVoid, some GetBool, some GetInt) = (self, self, self)
return (
selfs.0.property,
selfs.1.property,
selfs.2.property,
property
)
}
}