ocaml-ppx / ppx_deriving_yojson

A Yojson codec generator for OCaml.
MIT License
157 stars 46 forks source link

Add quoter #140

Closed sim642 closed 2 years ago

sim642 commented 3 years ago

I noticed that this deriver didn't work with a custom Result module (which is completely unrelated to the standard library one) and found out that no quoter is being used for sanitization. This PR adds that and should thus fix #81.

By also sanitizing the content of [@default ...] this fixes #132 as well.

sim642 commented 3 years ago

Hmm, I just tried this in an existing project and the quoting of [@default ...] does cause a small incompatibility. For example, previously (inside a record field) CodeQuery.structure [@default None_s], where Node_s is in CodeQuery but not opened here, compiled fine, because the generated function resolved its module based on the type (I'm assuming). After this change, one must be more explicit: CodeQuery.structure [@default CodeQuery.None_s] or just open CodeQuery to make None_s directly visible.

EDIT: Turns out this was easy to fix: just add an explicit type annotation for the default.