-
-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
bugSomething isn't workingSomething isn't working
Description
- I have read the documentation.
- I have read the limitations.
- I could not find my issue.
Describe the bug
Encoding of enums is missing
@Codable
enum Foo {
case test
}
// generates:
extension Foo: Decodable {
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: DecodingKeys.self)
guard container.allKeys.count == 1 else {
let context = DecodingError.Context(
codingPath: container.codingPath,
debugDescription: "Invalid number of keys found, expected one."
)
throw DecodingError.typeMismatch(Self.self, context)
}
let contentDecoder = try container.superDecoder(forKey: container.allKeys.first.unsafelyUnwrapped)
switch container.allKeys.first.unsafelyUnwrapped {
case DecodingKeys.test:
self = .test
}
}
}
extension Foo: Encodable {
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case .test:
break
}
}
}
extension Foo {
enum CodingKeys: String, CodingKey {
case test = "test"
}
enum DecodingKeys: String, CodingKey {
case test = "test"
}
}which means Foo.test just encodes to "{}" which is not useful and asymmetric to how it decodes
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working