Allow fields to occur in multiple constructors #2
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.
Currently, if multiple constructors of a datatype have a field, then multiple copies of the instances are generated.
For example:
This patch fixes this, by keeping track of the instances already made. While doing this, it also checks that multiple fields don't map to the same thing. In the above example, if the constructors instead had fields
aSize
andbSize
(both mapping toHasField "size" ...
), then that would be an error, even though they have the same type, since it may lead to surprising behaviour.A possible alternative approach could be extending
DeriveOverloadedRecordsParams
to specify what to do in case of conflicts. But just bailing is obviously much simpler and probably(?) usually the right answer, so that's what I went for.