Fix Equality To Be Consistent With Compare In Version #12
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.
This commit fixes the
def equals
method to be consistent with compare inVersion
. The reason for the inconsistency was thatdata-class
was generating anequals
method based off therepr
(e.g.this.repr == that.repr
), howevercompare
is encoded to determine logical equality of a binary API with respect to SemVer (sort of). That is to say,compare
compares two values by padding them to equal numeric length and then dropping the metadata value.Unfortunately, we can not simply override the
equals
method and use the@data
annotation (attempting to do so causes a compilation error). Thus this commit re-implements the methods from@data
, but only forVersion
. Data types which do not implementOrdered
do not need this special case treatment.The implementation of
compare
likely bares some further discussion. It creates a situation where thehashCode
and equality are unexpected for users cases other than comparing binary APIs.For example, if I want to create a
Set
ofVersion
values, this is likely unexpected behavior.Though there is no other way to implement
equals
andhashCode
such that it is consistent with the current implementation ofcompare
, however changingcompare
may likely have some unintended consequences as well.