@@ -279,6 +279,8 @@ and serialize_expr_of_tdecl t ~loc tdecl =
279279 serialize_expr_of_type_descr t ~loc core_type.ptyp_desc
280280 | None -> raise_errorf ~loc " Opaque types are not supported."
281281 end
282+ | Ptype_variant [] ->
283+ raise_errorf ~loc " ADTs with no constructors not supported"
282284 | Ptype_variant constrs ->
283285 test_constructor_mapping t constrs;
284286 let bindings, cases =
@@ -291,7 +293,7 @@ and serialize_expr_of_tdecl t ~loc tdecl =
291293 ) constrs
292294 |> List. unzip
293295 in
294- pexp_let ~loc Nonrecursive bindings @@ pexp_function ~loc cases
296+ pexp_let ~loc Nonrecursive bindings @@ pexp_function_cases ~loc cases
295297
296298 | Ptype_record labels ->
297299 let spec, patt, args = serialize_record t ~loc labels in
@@ -341,7 +343,7 @@ and serialize_expr_of_type_descr t ~loc = function
341343 ) rows
342344 |> List. unzip
343345 in
344- pexp_let ~loc Nonrecursive bindings @@ pexp_function ~loc cases
346+ pexp_let ~loc Nonrecursive bindings @@ pexp_function_cases ~loc cases
345347 | Ptyp_var core_type ->
346348 pexp_ident ~loc { loc; txt = Lident ( sprintf " __param_to_%s" core_type) }
347349 | Ptyp_arrow _ -> raise_errorf ~loc " Functions not supported"
@@ -351,6 +353,7 @@ and serialize_expr_of_type_descr t ~loc = function
351353 | Ptyp_class _
352354 | Ptyp_alias _
353355 | Ptyp_package _
356+ | Ptyp_open _
354357 | Ptyp_extension _ -> raise_errorf ~loc " Unsupported type descr"
355358
356359
@@ -534,7 +537,8 @@ and deserialize_expr_of_type_descr t ~loc = function
534537 | Ptyp_class _
535538 | Ptyp_alias _
536539 | Ptyp_package _
537- | Ptyp_extension _ -> raise_errorf ~loc " Unsupported type descr"
540+ | Ptyp_extension _
541+ | Ptyp_open _ -> raise_errorf ~loc " Unsupported type descr"
538542
539543let serialize_function_name ~loc ~driver name =
540544 let prefix = match name.txt with
@@ -586,28 +590,31 @@ let name_of_core_type ~prefix = function
586590 | { ptyp_desc = Ptyp_poly (_ , _ ); _} -> failwith " Ptyp_poly "
587591 | { ptyp_desc = Ptyp_package _ ; _} -> failwith " Ptyp_package "
588592 | { ptyp_desc = Ptyp_extension _ ; _} -> failwith " Ptyp_extension "
593+ | { ptyp_desc = Ptyp_open _ ; _} -> failwith " Ptyp_open "
589594
590595
591596let rec is_recursive_ct types = function
592597 | { ptyp_desc = Ptyp_var var ; _ } ->
593598 List. mem types var ~equal: String. equal
594- | { ptyp_desc = Ptyp_any ; _ } -> false
595- | { ptyp_desc = Ptyp_arrow _ ; _} -> false
596599 | { ptyp_desc = Ptyp_tuple cts ; _} -> List. exists ~f: (is_recursive_ct types) cts
597600 | { ptyp_desc = Ptyp_constr (l , cts ); _} ->
598601 List. mem types (string_of_ident_loc l).txt ~equal: String. equal ||
599602 List. exists ~f: (is_recursive_ct types) cts
600- | { ptyp_desc = Ptyp_object _ ; _} -> false
601- | { ptyp_desc = Ptyp_class _ ; _} -> false
602603 | { ptyp_desc = Ptyp_alias (c , _ ); _} -> is_recursive_ct types c
603604 | { ptyp_desc = Ptyp_variant (rows , _ , _ ); _} ->
604605 List. exists ~f: (fun row -> match row.prf_desc with
605606 | Rtag (_ , _ , cts ) -> List. exists ~f: (is_recursive_ct types) cts
606607 | Rinherit _ -> false
607608 ) rows
608609 | { ptyp_desc = Ptyp_poly (_ , ct ); _} -> is_recursive_ct types ct
609- | { ptyp_desc = Ptyp_package _ ; _} -> false
610- | { ptyp_desc = Ptyp_extension _ ; _} -> false
610+ | { ptyp_desc = (Ptyp_any
611+ | Ptyp_arrow _
612+ | Ptyp_object _
613+ | Ptyp_class _
614+ | Ptyp_package _
615+ | Ptyp_extension _
616+ | Ptyp_open _ ); _ } -> false
617+
611618
612619let is_recursive types = function
613620 | Ptype_abstract -> false
@@ -710,14 +717,16 @@ let make_recursive ~loc (e : expression) = function
710717 | true ->
711718 [% expr
712719 ( let f = ref None in
713- (fun t -> match ! f with
714- | None ->
715- let f' = [% e e] in f := Some f'; f' t
716- | Some f -> f t
717- ))
720+ (fun t ->
721+ match ! f with
722+ | None ->
723+ let f' = [% e e] in
724+ f := Some f';
725+ f' t
726+ | Some f -> f t
727+ ))
718728 ]
719729
720-
721730let to_protocol_str_type_decls t rec_flag ~loc tydecls =
722731 let (defs, is_recursive) =
723732 let is_recursive_f = is_recursive tydecls rec_flag in
0 commit comments