ppx_deriving_yojson
ppx_deriving_yojson copied to clipboard
infinite loop in presence of nonrec types
utop # #require "ppx_deriving_yojson";;
utop # type t = A | B [@@deriving yojson];;
utop # module M = struct type nonrec t = t [@@deriving yojson] end;;
utop # M.to_yojson A;;
(* never returns *)
^CInterrupted.
(* Work around by using different type name. *)
utop # module M = struct type u = t [@@deriving yojson] end;;
utop # M.u_to_yojson A;;
- : Yojson.Safe.json = `List [`String "A"]
Another way to see the problem:
utop # type t = {a:int};;
utop # type nonrec t = t [@@deriving yojson];;
type nonrec t = t
val to_yojson : t -> Yojson.Safe.json = <fun>
val of_yojson : Yojson.Safe.json -> t Ppx_deriving_yojson_runtime.error_or = <fun>
Last command shouldn't even compile since first definition of t lacks the corresponding derived functions.