Fix a bug with [@@deriving make] on type declarations sets #281
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.makebehave differently to the rest of the ppx universe in that regard.The fix will derive
makefor 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 typeserror differently which we use for the actual fix.I also updated the README to document how to use
ppx_deriving.makewith type declaration sets.