janestreet / ppx_yojson_conv

[@@deriving] plugin to generate Yojson conversion functions
MIT License
58 stars 8 forks source link

Can't access primitives in v0.16.0 #18

Open yongrenjie opened 1 year ago

yongrenjie commented 1 year ago

Since upgrading to v0.16.0 (released yesterday on OPAM), primitives such as int_of_yojson aren't visible. (Downgrading to v0.15.1 works!)

Minimal working example:

type t = {
  id: int;
}
[@@deriving of_yojson]

let () =
  let json = "{\"id\": 1}" in
  let t = t_of_yojson (Yojson.Safe.from_string json) in
  Printf.printf "id is: %d\n" t.id

Error:

File "bin/main.ml", line 2, characters 6-9:
2 |   id: int;
          ^^^
Error: Unbound value int_of_yojson
W95Psp commented 1 year ago

I have the same issue, but looking at commit https://github.com/janestreet/ppx_yojson_conv/commit/6a0456dc6c34946e5c65250bd30f7264ac2b905f, this breaking change seems intentional. The solution is thus to add an explicit open Ppx_yojson_conv_lib.Yojson_conv.Primitives. I guess this change was made because a PPX cannot distinguish between i.e. a user-defined option and OCaml's option...