-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bug with [@@deriving make] on type declarations sets #281
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tests behavior when deriving on mutually recursive types ocaml-ppx#272
@sim642 I'm pinging you in case you're interested in reviewing this. I'd recommend the per-commit view here, although I'm happy to split out the error handling bits if it makes the review easier. I was hoping to get the fix in before hitting a new |
sim642
reviewed
Apr 10, 2024
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
It used to fail and raise if the set contained a non record type. Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
95bb718
to
1573bb4
Compare
NathanReb
added a commit
to NathanReb/opam-repository
that referenced
this pull request
Apr 15, 2024
CHANGES: * Fix a bug in `[@@deriving make]` that caused errors when it was used on a set of type declarations containing at least one non record type. ocaml-ppx/ppx_deriving#281 (@NathanReb) * Embed errors instead of raising exceptions when generating code with `ppx_deriving.make` ocaml-ppx/ppx_deriving#281 (@NathanReb) * Remove `[%derive.iter ...]`, `[%derive.map ...]` and `[%derive.fold ...]` extensions ocaml-ppx/ppx_deriving#278 (Simmo Saan) * Port standard plugins to ppxlib registration and attributes ocaml-ppx/ppx_deriving#263 (Simmo Saan) * Optimize forwarding in eq and ord plugins ocaml-ppx/ppx_deriving#252 (Simmo Saan) * Delegate quoter to ppxlib ocaml-ppx/ppx_deriving#263 (Simmo Saan) * Introduce `Ppx_deriving_runtime.Stdlib` with OCaml >= 4.07. This module already exists in OCaml < 4.07 but was missing otherwise. ocaml-ppx/ppx_deriving#258 (Kate Deplaix)
NathanReb
added a commit
to NathanReb/ppx_deriving
that referenced
this pull request
Apr 26, 2024
This was broken by a change in ocaml-ppx#281 Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
NathanReb
added a commit
to NathanReb/ppx_deriving
that referenced
this pull request
Apr 26, 2024
This was broken by a change in ocaml-ppx#281 Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
This was referenced Apr 26, 2024
NathanReb
added a commit
to NathanReb/ppx_deriving
that referenced
this pull request
Apr 26, 2024
This was broken by a change in ocaml-ppx#281 Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #272.
There was a bug with
[@@deriving make]
that caused errors if it was used on a set of type declarations, recursive or non recursive, that contained a non record type.The deriver was applied to all type declarations in the set, regardless of where the attributes was attached and failed on the ones that weren't record types.
There is no particularly nice way to handle this in ppxlib, I assume the design decision was that one would only attach a single
[@@deriving ...]
attribute per set and the individual derivers would be responsible to decide which type declarations are relevant.The driver does allow attaching multiple
[@@deriving ...]
attributes in the same set but performs a merge of all of them so it can lead to confusing situations for the end user.With all that in mind, there is currently no proper way to tell to which individual type declarations the deriver was attached and even though there might be a hacky one, I'm not sure it would be desirable to use it as it's unlikely that other derivers do so and we probably don't want to have
ppx_deriving.make
behave differently to the rest of the ppx universe in that regard.The fix will derive
make
for all record types in the set if there is at least one, or will report errors about a misuse of thederiver otherwise.
The PR contains the initial regression test added in #273 by @shonfeder along with a small refactoring to properly embed errors. This allows us to treat regular errors, for example errors coming from misuse of
[@main]
or[@split]
, and themake can only be derived for record types
error differently which we use for the actual fix.I also updated the README to document how to use
ppx_deriving.make
with type declaration sets.