Skip to content

Fix unkeyed decoding cursor and colliding custom keys - #61

Open
letko-dmitry wants to merge 7 commits into
almazrafi:mainfrom
letko-dmitry:bugfix/fixes-and-cleanup
Open

letko-dmitry wants to merge 7 commits into
almazrafi:mainfrom
letko-dmitry:bugfix/fixes-and-cleanup

Conversation

@letko-dmitry

@letko-dmitry letko-dmitry commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

One commit per change, so any of them can be dropped:

  • Fix cursor handling in the unkeyed decoding container. decodeNil() moved to the next element even when it found a value, so decodeIfPresent read the element after the one it checked. A failed decode, nestedContainer or superDecoder moved on as well, unlike JSONDecoder. And coding paths in errors pointed one element too far: a bad second element of [1, "x"] was reported at index 2.
  • Resolve colliding custom keys deterministically. When a .custom key strategy maps several keys to one, the value came from whichever key the dictionary iterated first, so the result changed from run to run. The smallest original key now wins, as documented on .custom.
  • Fix a SwiftLint warning: SwiftLint 0.65 reports prefer_self_in_static_references in invalidFloatingPointValue.
  • Remove unused imports. The project's SwiftLint config enables the unused_import analyzer rule, and these files use nothing from Foundation.
  • Remove the unused isEmptyOrNil. Nothing calls it.
  • Share the setup of root encoders and decoders. The plain and WithConfiguration overloads duplicated it.
  • Remove availability checks below the deployment targets. Since Fixes for Xcode 27 #59 the minimums are iOS 15, macOS 12, tvOS 15 and watchOS 9, so the iOS 10 checks and their fatalError branches can't run.

Only the first two change observable behavior, and only for code that relied on the old cursor or key order. None of the changes makes encoding or decoding slower.

Measured as retired instructions in release builds on an M4, alternating A/B runs; differences within ±0.3% are noise.

@letko-dmitry
letko-dmitry marked this pull request as ready for review October 5, 2026 15:29
@letko-dmitry
letko-dmitry marked this pull request as draft October 5, 2026 15:49
@letko-dmitry
letko-dmitry force-pushed the bugfix/fixes-and-cleanup branch from aee93c0 to 3ef3683 Compare October 5, 2026 18:26
@letko-dmitry
letko-dmitry marked this pull request as ready for review October 5, 2026 18:34
@letko-dmitry

Copy link
Copy Markdown
Contributor Author

Should I split this PR into smaller ones or just close it for good? 😅

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.

1 participant