You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is also incorrect if one assumes the version scheme is pvp. From the specification for PVP,
Version number ordering is already defined by Cabal as the lexicographic ordering of the components. For example, 2.0.1 > 1.3.2, and 2.0.1.0 > 2.0.1. (The Data.Version.Version type and its Ord instance embody this ordering).
The important example there being that 2.0.1.0 > 2.0.1, not equal.
This means that the current compare definition for Version is incorrect if that version is supposed to represent a PVP version.
According to PVP, these should compare the same as,
scala>"1.0.0".compare("1.0.0.0")
valres2:Int=-2
I'm not exactly sure how this can easily be fixed. If for a moment we ignore the PVP use case and just focus on equals and hashCode, then we could resolve the issue using #12. This works, but as noted on the PR, the behavior here is likely unexpected for most users, though technically valid.
On the other hand, we could redefine compare to just be lexicographic ordering and introduce a new method for comparing the expressed binary API with respect to a specific VersionCompatibility value. This https://github.com/isomarcte/versions/tree/fix-pvp-ordering has some work towards that front, however I paused on it as I'm pretty concerned that changing the definition of compare may have negative effects on coursier as a whole, though this does seem like the more viable solution to me.
Another option would be to change the definition for compareand introduce a new type which is effectively a tuple a Version and a VersionCompatibility. This could provide methods to attempt to compare binary APIs with respect to a specific version scheme, making the behavior more explicit.
Thoughts?
The text was updated successfully, but these errors were encountered:
isomarcte
changed the title
The compare Implementation On Version Is Invalid For PVP And Is Incosistent With equals.
The compare Implementation On Version Is Inconsistent with equals And Invalid For PVP
Jun 26, 2021
The implementation of the
compare
method onVersion
is inconsistent withequals
.It is also inconsistent with
hashCode
.It is also incorrect if one assumes the version scheme is pvp. From the specification for PVP,
The important example there being that
2.0.1.0 > 2.0.1
, not equal.This means that the current
compare
definition forVersion
is incorrect if that version is supposed to represent a PVP version.According to PVP, these should compare the same as,
I'm not exactly sure how this can easily be fixed. If for a moment we ignore the PVP use case and just focus on
equals
andhashCode
, then we could resolve the issue using #12. This works, but as noted on the PR, the behavior here is likely unexpected for most users, though technically valid.On the other hand, we could redefine
compare
to just be lexicographic ordering and introduce a new method for comparing the expressed binary API with respect to a specificVersionCompatibility
value. This https://github.com/isomarcte/versions/tree/fix-pvp-ordering has some work towards that front, however I paused on it as I'm pretty concerned that changing the definition of compare may have negative effects oncoursier
as a whole, though this does seem like the more viable solution to me.Another option would be to change the definition for
compare
and introduce a new type which is effectively a tuple aVersion
and aVersionCompatibility
. This could provide methods to attempt to compare binary APIs with respect to a specific version scheme, making the behavior more explicit.Thoughts?
The text was updated successfully, but these errors were encountered: