Skip to content

Commit 7d0410b

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 d8c2af3 commit 7d0410b

File tree

3 files changed

+130
-83
lines changed

3 files changed

+130
-83
lines changed

Foundation/Codable.swift

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

0 commit comments

Comments
 (0)