janestreet / ppx_sexp_conv

Generation of S-expression conversion functions from type definitions
MIT License
89 stars 17 forks source link

Issues when `None` is redefined in scope of type declaration #35

Closed roddyyaga closed 2 years ago

roddyyaga commented 3 years ago

Example:

type none_type = None

type t = { foo: int } [@@deriving sexp]

Gives a confusing error:

3 | type t = { foo: int } [@@deriving sexp]
                    ^^^
Error: This variant pattern is expected to have type none_type
       The constructor Some does not belong to type none_type
Had errors, waiting for filesystem changes...

This is because the generated code uses None assuming it is a constructor for option. Editing the generated code to have let foo_field = ref Stdlib.Option.None instead of let foo_field = ref None fixes things. Could this be changed in the ppx? Happy to write a PR.

aalekseyev commented 2 years ago

I think this is fixed now.