Repository navigation
Conversation
Motivation: Encoding an empty array as a list member or dictionary value threw invalidTypeForItem. Those values start out as itemOrInnerList and only become an inner list once something is appended, so an empty array left the node undecided and inserting it into the parent failed. Modifications: Resolve itemOrInnerList to an empty inner list as soon as an unkeyed container is requested, since only an inner list can be encoded that way. Add an encoder test covering empty inner lists in lists and dictionaries. Result: Empty bare inner lists encode as "()".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
Encoding an empty array as a list member or a dictionary value throws
invalidTypeForItem. For example, a list field of[[1, 2, 3], []], or a dictionary field whose[Int]value is empty.These values start out as
itemOrInnerListand only become an inner list once the first element is appended. With nothing to append, the node is never resolved, and inserting it into the parent fails.()is a perfectly valid inner list, so this should just work.Modifications:
itemOrInnerListnode, resolve it to an empty inner list straight away. An unkeyed container can only mean an inner list at that point, so non-empty lists behave exactly as before.I did this in
unkeyedContainer()rather than ininsert(_:atKey:)so that an empty keyed struct still throws instead of quietly turning into().Result:
Empty inner lists encode as
().Tested locally on macOS with Swift 6.4.1,
swift testpasses.