Skip to content

Commit

Permalink
don't apply () for nonrecursive types in derivers
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtori committed Oct 14, 2024
1 parent 25ffc33 commit e643ee2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ppx/ppx_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -601,18 +601,22 @@ let transform ?kind () =

let impl ?kind str = (transform ?kind ())#structure str

let deriver_str_gen kind meth ~loc ~path:_ (_rec_flag, l) path input output errors params section name
let deriver_str_gen kind meth ~loc ~path:_ (rec_flag, l) path input output errors params section name
descr security register hide input_example output_example debug =
let options = options loc in
let sname = match l with t :: _ -> Some (t.ptype_name.txt ^ "_s") | [] -> None in
let aux e = match e.pexp_desc with
| Pexp_construct ({txt=Lident "::"; _}, _) -> raw e
| _ -> [%expr EzAPI.Json [%e e]] in
let input, output, tname = match meth, l with
| _, [ t_input; t_output ] ->
| _, [ t_input; t_output ] when rec_flag = Recursive ->
[%expr EzAPI.Json ([%e evar ~loc (t_input.ptype_name.txt ^ "_enc")] ())],
[%expr EzAPI.Json ([%e evar ~loc (t_output.ptype_name.txt ^ "_enc")] ())],
t_input.ptype_name.txt
| _, [ t_input; t_output ] ->
[%expr EzAPI.Json [%e evar ~loc (t_input.ptype_name.txt ^ "_enc")]],
[%expr EzAPI.Json [%e evar ~loc (t_output.ptype_name.txt ^ "_enc")]],
t_input.ptype_name.txt
| ("get" | "put"), t :: _ ->
Option.fold ~none:options.input ~some:aux input,
[%expr EzAPI.Json [%e evar ~loc (t.ptype_name.txt ^ "_enc")]],
Expand Down

0 comments on commit e643ee2

Please sign in to comment.