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

Record-wrapping newtypes should produce MoatStruct #88

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

tadfisher
Copy link
Collaborator

Example:

newtype Newtype = Newtype {newtypeField :: Text}

Aeson serializes this as a JSON object like:

{"newtypeField":"foo"}

But Moat generates Kotlin code that deserializes this as its wrapped value, so we expect "foo" on the wire. The Mercury codebase has a ton of newtypeToStruct calls to coerce these into MoatStruct, and backend engs don't really know about this nuance so it's forgotten.

This changes mkNewtype to produce a MoatStruct if the wrapped constructor is a record constructor. In addition, this lifts the restriction that newtypes can't wrap records with multiple fields.

I am not sure if this breaks Swift codegen. If I'm correct about Aeson's output, then generating untagged structs shouldn't make a difference.

@tadfisher tadfisher requested a review from chiroptical August 15, 2024 18:17
@tadfisher tadfisher merged commit 1b4217b into master Aug 15, 2024
21 checks passed
@tadfisher tadfisher deleted the tad/newtype-records branch August 15, 2024 18:33
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.

2 participants