SwiftyLab / MetaCodable

Supercharge Swift's Codable implementations with macros meta-programming.
https://swiftpackageindex.com/SwiftyLab/MetaCodable/main/documentation/metacodable
MIT License
604 stars 22 forks source link

[Bug] Macro expansion does not compile when enabling the 'Existential Any' upcoming feature. #27

Closed Midbin closed 10 months ago

Midbin commented 11 months ago

When using the .enableUpcomingFeature("ExistentialAny") for building a package the generated Macro code does not compile.

@Codable
struct Test {
  var test: String
}

Is expanded to:

extension Test: Decodable {
    init(from decoder: Decoder) throws {  //<- Error: Use of protocol 'Decoder' as a type must be written 'any Decoder'
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.test = try container.decode(String.self, forKey: CodingKeys.test)
    }
}

extension Test: Encodable {
    func encode(to encoder: Encoder) throws {  // <- Error: Use of protocol 'Decoder' as a type must be written 'any Decoder'
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(self.test, forKey: CodingKeys.test)
    }
}

extension Test {
    enum CodingKeys: String, CodingKey {
        case test = "test"
    }
}