Skip to content

Commit a0f5587

Browse files
committed
Break ambiguity for types conforming to both UEC and SVEC
If an encoding container conforms to _both_ UEC and SVEC and does not itself implement support for [U]Int128, there is an ambiguity between the two default implementations. Add additional defaults defined on the intersection of the protocols to resolve this.
1 parent 0e47b2d commit a0f5587

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

stdlib/public/core/Codable.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7102,3 +7102,29 @@ extension SingleValueDecodingContainer {
71027102
)
71037103
}
71047104
}
7105+
7106+
// Default implementations for types with stricter availability than SVEC & UEC
7107+
// We need these to break ambiguity when an encoding container conforms to both.
7108+
extension SingleValueEncodingContainer where Self: UnkeyedEncodingContainer {
7109+
@available(SwiftStdlib 6.0, *)
7110+
public mutating func encode(_ value: Int128) throws {
7111+
throw EncodingError.invalidValue(
7112+
value,
7113+
EncodingError.Context(
7114+
codingPath: codingPath,
7115+
debugDescription: "Encoder has not implemented support for Int128"
7116+
)
7117+
)
7118+
}
7119+
7120+
@available(SwiftStdlib 6.0, *)
7121+
public mutating func encode(_ value: UInt128) throws {
7122+
throw EncodingError.invalidValue(
7123+
value,
7124+
EncodingError.Context(
7125+
codingPath: codingPath,
7126+
debugDescription: "Encoder has not implemented support for UInt128"
7127+
)
7128+
)
7129+
}
7130+
}

0 commit comments

Comments
 (0)