Skip to content

Conversation

@arnauddorgans
Copy link
Contributor

The PR removes useless Codable requirements

@bsneed
Copy link
Contributor

bsneed commented Jul 13, 2025

can you elaborate on why you needed to make this change, or was it purely for correctness?

@arnauddorgans
Copy link
Contributor Author

@bsneed it forces us to write useless Decodable conformances on objects that are not decodable
e.g.

extension AnalyticsClient {
    struct Context: Codable {
        let value: Any
        let encode: (inout SingleValueEncodingContainer) throws -> Void

        init<T: Encodable>(_ value: T) {
            self.value = value
            self.encode = { try $0.encode(value) }
        }

        init(from decoder: any Decoder) throws {
            // Waiting for https://github.com/segmentio/analytics-swift/pull/386 to me merged
            throw DecodingError.dataCorrupted(.init(
                codingPath: decoder.codingPath,
                debugDescription: "Decodable is not used"
            ))
        }

        func encode(to encoder: any Encoder) throws {
            var container = encoder.singleValueContainer()
            try encode(&container)
        }
    }
}

@bsneed bsneed merged commit bcc4277 into segmentio:main Jul 30, 2025
1 check passed
@bsneed
Copy link
Contributor

bsneed commented Jul 30, 2025

Thanks for the explanation @arnauddorgans

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants