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

Infinite <<loop>> when using named fields #211

Open
paulyoung opened this issue Apr 23, 2020 · 5 comments
Open

Infinite <<loop>> when using named fields #211

paulyoung opened this issue Apr 23, 2020 · 5 comments

Comments

@paulyoung
Copy link
Contributor

This data type:

data Foo
  = Bar Foo
  | Baz Foo
  deriving (Generic, ToJSON, ToSchema)

Produces this JSON:

{
  "swagger": "2.0",
  "info": {
    "version": "",
    "title": ""
  },
  "definitions": {
    "Foo": {
      "minProperties": 1,
      "maxProperties": 1,
      "type": "object",
      "properties": {
        "Baz": {
          "$ref": "#/definitions/Foo"
        },
        "Bar": {
          "$ref": "#/definitions/Foo"
        }
      }
    }
  },
  "paths": {}
}

However, if I attempt to name the field like this:

data Foo
  = Bar { _1 :: Foo }
  | Baz { _2 :: Foo }
  deriving (Generic, ToJSON, ToSchema)

I get:

<<loop>>
@paulyoung
Copy link
Contributor Author

paulyoung commented Apr 23, 2020

My motivation for using named fields is in an attempt to have the required field populated and managed for me.

I’m hoping that I can later use that to know which type arguments were a Maybe

@fisx
Copy link
Collaborator

fisx commented Apr 30, 2020

looks like a legitimate bug to me. do you have time to work on fixing this?

@paulyoung
Copy link
Contributor Author

@Gabriel439 suggested that this could potentially be fixed using the same approach as in dhall-lang/dhall-haskell#1660

@paulyoung
Copy link
Contributor Author

I linked to the issue but the PR that fixes it is dhall-lang/dhall-haskell#1825

@paulyoung
Copy link
Contributor Author

It looks like those changes allow erroring out and breaking the loop but don't actually allow generic deriving of recursive data types.

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

No branches or pull requests

2 participants