melange-community / melange-json

Compositional JSON encode/decode library and PPX for Melange and OCaml
GNU Lesser General Public License v3.0
15 stars 2 forks source link

ppx: generated code for variants depends on runtime on Melange side, but not on OCaml side #34

Open jchavarri opened 4 hours ago

jchavarri commented 4 hours ago

It seems that the Melange ppx requires string_to_json:

https://github.com/melange-community/melange-json/blob/14453795349684cbb8bb201b4fd2c9107b0dc7da/ppx/browser/ppx_deriving_json_js.ml#L197

while the OCaml implementation does not:

https://github.com/melange-community/melange-json/blob/14453795349684cbb8bb201b4fd2c9107b0dc7da/ppx/native/ppx_deriving_json_native.ml#L209-L224

This leads to some confusing situation for "universal" code, where not adding open Ppx_deriving_json_runtime.Primitives leads to errors like Unbound value string_to_json on the Melange build, but adding it leads to unused open Ppx_deriving_json_runtime.Primitives on the OCaml build.

I wonder if there's a way around this, besides silencing the warnings?

andreypopp commented 4 hours ago

can make use of string_to_json on OCaml side as well?

andreypopp commented 4 hours ago

Or actually let's qualify usage of string_to_json in JS ppx, that would be the correct fix as string_to_json might be overridden by user code