janwirth / elm-coder-generator

Generate encoders and decoders for elm/json
MIT License
12 stars 1 forks source link

Decoder for non-concrete types are not passed to helper #8

Open qwfy opened 4 years ago

qwfy commented 4 years ago

Currently, generated code for the following type:

type Token a
    = Number a

is:

decodeToken decodeA =
    Decode.field "Constructor" Decode.string |> Decode.andThen decodeTokenHelp

decodeTokenHelp constructor =
    case constructor of
        "Number" ->
            Decode.map
                Number
                (Decode.field "A1" decodeA)

which is incorrect, (missing decodeA in decodeTokenHelp), the correct version should be:

decodeToken decodeA =
    Decode.field "Constructor" Decode.string |> Decode.andThen (decodeTokenHelp decodeA)

decodeTokenHelp decodeA constructor =
    case constructor of
        "Number" ->
            Decode.map
                Number
                (Decode.field "A1" decodeA)
janwirth commented 4 years ago

Thank you for documenting this issue. I will provide a testing & development workflow if you feel up to it.