Skip to content

Commit e1007a2

Browse files
author
Itai Ferber
committed
Make coding paths non-optional
For the benefit of unkeyed containers, coding paths currently contain optional `CodingKey`s — unkeyed containers are allowed to report a `nil` key in a path. However, this is unhelpful for debugging purposes, or inspecting the coding path for context, since any unkeyed container simply reports `nil`, whether it’s at index 1 or 1000. Now all containers are required to report a non-optional CodingKey for their segment of the coding path, and coding paths are now exposed as `[CodingKey]`.
1 parent c063d49 commit e1007a2

File tree

6 files changed

+310
-225
lines changed

6 files changed

+310
-225
lines changed

stdlib/public/SDK/Foundation/Codable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal extension DecodingError {
2929
/// - parameter expectation: The type expected to be encountered.
3030
/// - parameter reality: The value that was encountered instead of the expected type.
3131
/// - returns: A `DecodingError` with the appropriate path and debug description.
32-
internal static func _typeMismatch(at path: [CodingKey?], expectation: Any.Type, reality: Any) -> DecodingError {
32+
internal static func _typeMismatch(at path: [CodingKey], expectation: Any.Type, reality: Any) -> DecodingError {
3333
let description = "Expected to decode \(expectation) but found \(_typeDescription(of: reality)) instead."
3434
return .typeMismatch(expectation, Context(codingPath: path, debugDescription: description))
3535
}

0 commit comments

Comments
 (0)