mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* Support extensions including conditional conformance * Correct access modifiers * More correct lookup for the synthesized declarations * Avoid printing decls in nested types (rdar://98025945)
49 lines
874 B
Plaintext
49 lines
874 B
Plaintext
|
|
struct User {
|
|
let firstName: String
|
|
let lastName: String?
|
|
}
|
|
|
|
extension User: Codable {
|
|
}
|
|
|
|
|
|
struct Generic<Value> {
|
|
var value: Value
|
|
}
|
|
|
|
extension Generic {
|
|
}
|
|
|
|
extension Generic: Codable where Value: Codable {
|
|
|
|
private enum CodingKeys: CodingKey {
|
|
case value
|
|
}
|
|
|
|
init(from decoder: any Decoder) throws {
|
|
let container: KeyedDecodingContainer<Generic<Value>.CodingKeys> = try decoder.container(keyedBy: Generic<Value>.CodingKeys.self)
|
|
|
|
self.value = try container.decode(Value.self, forKey: Generic<Value>.CodingKeys.value)
|
|
|
|
}
|
|
|
|
func encode(to encoder: any Encoder) throws {
|
|
var container = encoder.container(keyedBy: Generic<Value>.CodingKeys.self)
|
|
|
|
try container.encode(self.value, forKey: Generic.CodingKeys.value)
|
|
}
|
|
}
|
|
|
|
|
|
struct Outer {
|
|
struct Inner {
|
|
let value: Int
|
|
}
|
|
}
|
|
|
|
extension Outer.Inner: Codable {
|
|
}
|
|
|
|
|