ppx_deriving_yojson icon indicating copy to clipboard operation
ppx_deriving_yojson copied to clipboard

infinite loop in presence of nonrec types

Open agarwal opened this issue 8 years ago • 1 comments

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"]

agarwal avatar Sep 21 '17 14:09 agarwal

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.

agarwal avatar Sep 21 '17 16:09 agarwal