Skip to content

Commit

Permalink
Only pass type declaration once to gen_combinator_for_record
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Ferris <[email protected]>

Co-authored-by: Nathan Rebours <[email protected]>
  • Loading branch information
patricoferris and NathanReb committed Nov 30, 2024
1 parent cb22c1c commit c29c221
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/gen/gen_ast_builder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct
in
(str, (Format.asprintf "%a" A.ctyp return_type, sign))

let gen_combinator_for_record path ~prefix return_type attrs lds =
let gen_combinator_for_record path ~prefix return_type lds =
let fields =
List.map lds ~f:(fun ld -> fqn_longident path ld.pld_name.txt)
in
Expand Down Expand Up @@ -180,15 +180,15 @@ struct
M.expr "fun ~loc -> %a" A.expr body
else body
in
let return_type = core_type_of_return_type return_type in
let return_ctyp = core_type_of_return_type return_type in
let typ =
let l =
List.filter funcs ~f:(fun (_, f) -> f <> "loc" && f <> "attributes")
in
match l with
| [ (c, _) ] -> M.ctyp "%a -> %a" A.ctyp c A.ctyp return_type
| [ (c, _) ] -> M.ctyp "%a -> %a" A.ctyp c A.ctyp return_ctyp
| _ ->
List.fold_right l ~init:return_type ~f:(fun (typ, func) acc ->
List.fold_right l ~init:return_ctyp ~f:(fun (typ, func) acc ->
M.ctyp "%s:%a -> %a" func A.ctyp typ A.ctyp acc)
in
let typ =
Expand All @@ -207,10 +207,10 @@ struct
A.ctyp typ
(doc_comment
~function_name:(function_name_of_path path)
~node_name:(Format.asprintf "%a" A.ctyp return_type)
attrs)
~node_name:(Format.asprintf "%a" A.ctyp return_ctyp)
return_type.ptype_attributes)
in
(str, (Format.asprintf "%a" A.ctyp return_type, sign))
(str, (Format.asprintf "%a" A.ctyp return_ctyp, sign))

let gen_td ?wrapper path td =
if is_loc path then []
Expand All @@ -227,7 +227,7 @@ struct
~f:(gen_combinator_for_constructor ~wrapper path ~prefix td))
| Ptype_record lds ->
let prefix = prefix_of_record lds in
[ gen_combinator_for_record path ~prefix td td.ptype_attributes lds ]
[ gen_combinator_for_record path ~prefix td lds ]
| Ptype_abstract | Ptype_open -> []
end

Expand Down

0 comments on commit c29c221

Please sign in to comment.