Skip to content

Commit 41ed298

Browse files
committed
ppx: flatten tuples in poly constructors
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
1 parent a47cc59 commit 41ed298

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- PPX: Add `yojson` as runtime dep for the native version
66
([#15](https://github.com/melange-community/melange-json/pull/15))
77
- PPX: Rename `[@json.as]` to `[@json.name]`
8+
- PPX: change JSON representation of polyvariants, make it compatible with
9+
ppx_deriving_yojson and ppx_yojson_conv
10+
([#27](https://github.com/melange-community/melange-json/pull/27))
811

912
## 1.3.0 (2024-08-28)
1013

ppx/tools/ppx_deriving_tools.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ let register_combined ?deps name derivings =
115115
module Schema = struct
116116
let repr_row_field field =
117117
match field.prf_desc with
118-
| Rtag (id, _, ts) -> `Rtag (id, ts)
118+
| Rtag (id, _, []) -> `Rtag (id, [])
119+
| Rtag (id, _, [ { ptyp_desc = Ptyp_tuple ts; _ } ]) -> `Rtag (id, ts)
120+
| Rtag (id, _, [ t ]) -> `Rtag (id, [ t ])
121+
| Rtag (_, _, _ :: _) ->
122+
not_supported ~loc:field.prf_loc
123+
"polyvariant constructor with more than one argument"
119124
| Rinherit { ptyp_desc = Ptyp_constr (id, ts); _ } ->
120125
`Rinherit (id, ts)
121126
| Rinherit _ ->

0 commit comments

Comments
 (0)