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)
50 lines
1.5 KiB
Plaintext
50 lines
1.5 KiB
Plaintext
|
|
enum Payload: Codable {
|
|
case plain(String)
|
|
case pair(key: String, value: String)
|
|
}
|
|
|
|
enum Payload_D: Decodable {
|
|
case plain(String)
|
|
case pair(key: String, value: String)
|
|
|
|
private enum CodingKeys: CodingKey {
|
|
case plain
|
|
case pair
|
|
}
|
|
|
|
private enum PlainCodingKeys: CodingKey {
|
|
case _0
|
|
}
|
|
|
|
private enum PairCodingKeys: CodingKey {
|
|
case key
|
|
case value
|
|
}
|
|
|
|
init(from decoder: any Decoder) throws {
|
|
let container = try decoder.container(keyedBy: Payload_D.CodingKeys.self)
|
|
|
|
var allKeys = ArraySlice(container.allKeys)
|
|
|
|
guard let onlyKey = allKeys.popFirst(), allKeys.isEmpty else {
|
|
throw DecodingError.typeMismatch(Payload_D.self, DecodingError.Context.init(codingPath: container.codingPath, debugDescription: "Invalid number of keys found, expected one.", underlyingError: nil))
|
|
}
|
|
switch onlyKey {
|
|
case .plain:
|
|
let nestedContainer = try container.nestedContainer(keyedBy: Payload_D.PlainCodingKeys.self, forKey: Payload_D.CodingKeys.plain)
|
|
|
|
self = Payload_D.plain(try nestedContainer.decode(String.self, forKey: Payload_D.PlainCodingKeys._0))
|
|
case .pair:
|
|
let nestedContainer = try container.nestedContainer(keyedBy: Payload_D.PairCodingKeys.self, forKey: Payload_D.CodingKeys.pair)
|
|
|
|
self = Payload_D.pair(key: try nestedContainer.decode(String.self, forKey: Payload_D.PairCodingKeys.key), value: try nestedContainer.decode(String.self, forKey: Payload_D.PairCodingKeys.value))
|
|
}
|
|
}
|
|
}
|
|
|
|
enum Payload_E: Encodable {
|
|
case plain(String)
|
|
case pair(key: String, value: String)
|
|
}
|