Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OptionalParent does not en/decode correctly #527

Open
jdmcd opened this issue Jul 26, 2022 · 2 comments
Open

OptionalParent does not en/decode correctly #527

jdmcd opened this issue Jul 26, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@jdmcd
Copy link
Member

jdmcd commented Jul 26, 2022

The anyValueType eraser in Fields+Codable is coalescing the double-optional of OptionalParent.Value to a single optional, causing it to improperly decode when passed around via Codable.

@jdmcd jdmcd added the bug Something isn't working label Jul 26, 2022
@gwynne
Copy link
Member

gwynne commented Jul 26, 2022

The issue is further exacerbated by Swift generating incorrect decoding logic when it encounters property wrappers with optional wrapped values, always decoding the corresponding coding key unconditionally. As most encoders encode nothing for nil values, and decoders verify the presence of a given key when asked to decode it regardless of whether it represents a nested container, a missing key error is inevitably thrown if the original encoded value was nil. The error occurs in the context of the container before the property wrapper’s own Codable conformance can ever come into play, with the various possible workarounds each having nontrivial drawbacks.

This matters for the problem described herein because if the wrappers were correctly decoded, there would be no need for the type erasure in the first place.

@gwynne
Copy link
Member

gwynne commented Jul 26, 2022

Additional note: As with some other outstanding concerns around property wrappers, the formalization of API vs. implementation detail property wrappers in SE-0293 theoretically cleared the path to a solution, but there was no follow up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants