-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix DiffTreeVertexDiffTerm definition to be a valid protobuf object.
We define the DiffTreeVertex protobuf message like so: ```protobuf message DiffTreeVertex { int32 diff_vertex_id = 1; oneof diff_term { DeletedTerm deleted = 2; InsertedTerm inserted = 3; ReplacedTerm replaced = 4; MergedTerm merged = 5; } } ``` This is turned into two Haskell types, a toplevel `DiffTreeVertex` type and a `DiffTreeVertexDiffTerm` type that represents the anonymous `oneof` type. Said types looked like so: ```haskell data DiffTreeVertexDiffTerm = Deleted (Maybe DeletedTerm) | Inserted (Maybe InsertedTerm) | Replaced (Maybe ReplacedTerm) | Merged (Maybe MergedTerm) deriving stock (Eq, Ord, Show, Generic) deriving anyclass (Proto3.Message, Proto3.Named, NFData) ``` This is the wrong representation, as it neglects to account for the fact that options could be added to the `diff_term` stanza. A sum type does not provide enough constructors to handle the case of when none of `deleted`, `inserted`, `replaced` etc. is `Just` anything. A more correct definition follows: ```haskell data DiffTreeVertexDiffTerm = DiffTreeVertexDiffTerm { deleted :: Maybe DeletedTerm , inserted :: Maybe InsertedTerm , replaced :: Maybe ReplacedTerm , merged :: Maybe MergedTerm } ``` This patch applies the above change, using `-XPatternSynonyms` to provide backwards-compatible API shims. Though this changes JSON output format (through the `ToJSON` instance), it should have no bearing on backwards compatibility in protobuf objects, since there is no way to consume diff trees as protobufs as of this writing. Fixes #168.
- Loading branch information
Showing
2 changed files
with
48 additions
and
46 deletions.
There are no files selected for viewing
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
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