Handle unparsed non-optional complex property types#554
Merged
Conversation
Contributor
Author
…on-optional nested decoding.
Member
natecook1000
left a comment
There was a problem hiding this comment.
@gwynne Thanks so much for this fix! I believe your change to decode(_:forKey:) is sufficient to solve the problem. Unless we can create a test that exercises the new allKeys, let's revert that back to a fatal error.
Can you also switch to 2-space indenting? Thanks!
Contributor
Author
|
@natecook1000 Well, I tried to come up with a test that would exercise the |
…ble given the fix to decode(_:forKey:)
Member
|
@swift-ci Please test |
|
(thanks @gwynne for fixing this, much obliged!) |
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.
As initially demonstrated in #553, the existing
ArgumentDecoderlogic fails when presented with a property which:This occurs because while the actual property in question is properly assessed as having
.defaultValueas anInputOrigin, the request for a keyed decoding container bypasses the logic which would otherwise return said default value, and since theArgumentDefinitionlogic is (correctly) not recursive, the type fails to decode any keys it contains due to a "missing value".The most straightforward solution I could find, one which covers all cases without negatively affecting handling of parsed properties (to the best of my ability to determine), was to apply the "default value" handling from the
decodeIfPresent<T>(_:forKey:)method of the keyed decoding container (which ensured that optional properties of this sort already worked correctly) to the more fundamental "bottleneck"decode<T>(_:forKey:)method as well, modified to throw awrongTypeerror instead of returning nil on type mismatch.I additionally added a functioning
allKeysproperty accessor for additional robustness against customDecodable.init(from:)implementations. (The choice not to do the same fornestedContainer(keyedBy:),nestedUnkeyedContainer(),superDecoder(), andsuperDecoder(forKey:)was simply pragmatic - it's not even close to worth the effort.)Fixes #553
Checklist