Skip to content

Commit cbf9cb2

Browse files
Break ambiguity for types conforming to both UEC and SVEC (#72800)
* 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. * Update abi tests for new ambiguity breakers.
1 parent 1b5d61b commit cbf9cb2

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

stdlib/public/core/Codable.swift

+26
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+
}

test/abi/macOS/arm64/stdlib.swift

+2
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ Added: _$ss28SingleValueDecodingContainerPsE6decodeys6Int128VAEmKF
271271
Added: _$ss28SingleValueEncodingContainerP6encodeyys6Int128VKFTj
272272
Added: _$ss28SingleValueEncodingContainerP6encodeyys6Int128VKFTq
273273
Added: _$ss28SingleValueEncodingContainerPsE6encodeyys6Int128VKF
274+
Added: _$ss28SingleValueEncodingContainerPss07UnkeyedcD0RzrlE6encodeyys6Int128VKF
274275
Added: _$ss30KeyedDecodingContainerProtocolP15decodeIfPresent_6forKeys6Int128VSgAFm_0I0QztKFTj
275276
Added: _$ss30KeyedDecodingContainerProtocolP15decodeIfPresent_6forKeys6Int128VSgAFm_0I0QztKFTq
276277
Added: _$ss30KeyedDecodingContainerProtocolP6decode_6forKeys6Int128VAFm_0G0QztKFTj
@@ -408,6 +409,7 @@ Added: _$ss28SingleValueDecodingContainerPsE6decodeys7UInt128VAEmKF
408409
Added: _$ss28SingleValueEncodingContainerP6encodeyys7UInt128VKFTj
409410
Added: _$ss28SingleValueEncodingContainerP6encodeyys7UInt128VKFTq
410411
Added: _$ss28SingleValueEncodingContainerPsE6encodeyys7UInt128VKF
412+
Added: _$ss28SingleValueEncodingContainerPss07UnkeyedcD0RzrlE6encodeyys7UInt128VKF
411413
Added: _$ss30KeyedDecodingContainerProtocolP15decodeIfPresent_6forKeys7UInt128VSgAFm_0I0QztKFTj
412414
Added: _$ss30KeyedDecodingContainerProtocolP15decodeIfPresent_6forKeys7UInt128VSgAFm_0I0QztKFTq
413415
Added: _$ss30KeyedDecodingContainerProtocolP6decode_6forKeys7UInt128VAFm_0G0QztKFTj

test/abi/macOS/x86_64/stdlib.swift

+2
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ Added: _$ss28SingleValueDecodingContainerPsE6decodeys6Int128VAEmKF
271271
Added: _$ss28SingleValueEncodingContainerP6encodeyys6Int128VKFTj
272272
Added: _$ss28SingleValueEncodingContainerP6encodeyys6Int128VKFTq
273273
Added: _$ss28SingleValueEncodingContainerPsE6encodeyys6Int128VKF
274+
Added: _$ss28SingleValueEncodingContainerPss07UnkeyedcD0RzrlE6encodeyys6Int128VKF
274275
Added: _$ss30KeyedDecodingContainerProtocolP15decodeIfPresent_6forKeys6Int128VSgAFm_0I0QztKFTj
275276
Added: _$ss30KeyedDecodingContainerProtocolP15decodeIfPresent_6forKeys6Int128VSgAFm_0I0QztKFTq
276277
Added: _$ss30KeyedDecodingContainerProtocolP6decode_6forKeys6Int128VAFm_0G0QztKFTj
@@ -408,6 +409,7 @@ Added: _$ss28SingleValueDecodingContainerPsE6decodeys7UInt128VAEmKF
408409
Added: _$ss28SingleValueEncodingContainerP6encodeyys7UInt128VKFTj
409410
Added: _$ss28SingleValueEncodingContainerP6encodeyys7UInt128VKFTq
410411
Added: _$ss28SingleValueEncodingContainerPsE6encodeyys7UInt128VKF
412+
Added: _$ss28SingleValueEncodingContainerPss07UnkeyedcD0RzrlE6encodeyys7UInt128VKF
411413
Added: _$ss30KeyedDecodingContainerProtocolP15decodeIfPresent_6forKeys7UInt128VSgAFm_0I0QztKFTj
412414
Added: _$ss30KeyedDecodingContainerProtocolP15decodeIfPresent_6forKeys7UInt128VSgAFm_0I0QztKFTq
413415
Added: _$ss30KeyedDecodingContainerProtocolP6decode_6forKeys7UInt128VAFm_0G0QztKFTj

0 commit comments

Comments
 (0)