Skip to content

Commit

Permalink
ppx: flatten tuples in poly constructors
Browse files Browse the repository at this point in the history
We want to flatten the representation of polyvariants with tuple payload
and represent them as [TAG, ARG1, ARG2, ...] instead of [TAG, [ARG1, ARG2, ...]].

Fixes #24
  • Loading branch information
andreypopp committed Oct 7, 2024
1 parent 8e617a6 commit c5647f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
([#13](https://github.com/melange-community/melange-json/pull/13))
- PPX: Add `yojson` as runtime dep for the native version
([#15](https://github.com/melange-community/melange-json/pull/15))
- PPX: change JSON representation of polyvariants, make it compatible with
ppx_deriving_yojson and ppx_yojson_conv
([#27](https://github.com/melange-community/melange-json/pull/27))

## 1.3.0 (2024-08-28)

Expand Down
7 changes: 6 additions & 1 deletion ppx/tools/ppx_deriving_tools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ let register_combined ?deps name derivings =
module Schema = struct
let repr_row_field field =
match field.prf_desc with
| Rtag (id, _, ts) -> `Rtag (id, ts)
| Rtag (id, _, []) -> `Rtag (id, [])
| Rtag (id, _, [ { ptyp_desc = Ptyp_tuple ts; _ } ]) -> `Rtag (id, ts)
| Rtag (id, _, [ t ]) -> `Rtag (id, [ t ])
| Rtag (_, _, _ :: _) ->
not_supported ~loc:field.prf_loc
"polyvariant constructor with more than one argument"
| Rinherit { ptyp_desc = Ptyp_constr (id, ts); _ } ->
`Rinherit (id, ts)
| Rinherit _ ->
Expand Down

0 comments on commit c5647f7

Please sign in to comment.