Skip to content

fix: Bind field names in prettyEnumCoding - #96

Closed
alt-romes wants to merge 1 commit into
MercuryTechnologies:masterfrom
alt-romes:master
Closed

alt-romes wants to merge 1 commit into
MercuryTechnologies:masterfrom
alt-romes:master

Conversation

@alt-romes

Copy link
Copy Markdown

The previously produced code didn't bind the field names in the enum case, leading to compile errors

== Example

For

data Keyword
  = RawKw Text
  | InstanceLabelKw
  | RefKw { refKwDefName :: Text
          , refKwQuery   :: Query Void
          }

The diff in generated code is:

    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        switch (self) {
            case let .rawKw(value):
                try container.encode("rawKw", forKey: .tag)
                try value.encode(to: encoder)
            case .instanceLabelKw:
                try container.encode("instanceLabelKw", forKey: .tag)
-           case let .refKw:
+           case let .refKw(refKwDefName, refKwQuery):
                try container.encode("refKw", forKey: .tag)
                try container.encode(refKwDefName, forKey: .refKwDefName)
                try container.encode(refKwQuery, forKey: .refKwQuery)
        }
    }

The previously produced code didn't bind the field names in the enum
case, leading to compile errors

== Example

For

```haskell
data Keyword
  = RawKw Text
  | InstanceLabelKw
  | RefKw { refKwDefName :: Text
          , refKwQuery   :: Query Void
          }
```

The diff in generated code is:
```diff
    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        switch (self) {
            case let .rawKw(value):
                try container.encode("rawKw", forKey: .tag)
                try value.encode(to: encoder)
            case .instanceLabelKw:
                try container.encode("instanceLabelKw", forKey: .tag)
-           case let .refKw:
+           case let .refKw(refKwDefName, refKwQuery):
                try container.encode("refKw", forKey: .tag)
                try container.encode(refKwDefName, forKey: .refKwDefName)
                try container.encode(refKwQuery, forKey: .refKwQuery)
        }
    }
```
@tadfisher

Copy link
Copy Markdown
Collaborator

Applied in #100, thanks :)

@tadfisher tadfisher closed this Jun 11, 2026
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