Skip to content

Commit

Permalink
Make the comparison of LF version total (#20102)
Browse files Browse the repository at this point in the history
This quick fix addresses a crash issue when comparing V1 with V2 LF Versions unexpectedly.
In the future, we should consider removing this ordering altogether. See issue #20101.
  • Loading branch information
remyhaemmerle-da authored Oct 15, 2024
1 parent 255d84f commit 7bc65fd
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ object LanguageVersion {

def assertFromString(s: String): LanguageVersion = data.assertRight(fromString(s))

// TODO https://github.com/digital-asset/daml/issues/20101
// Drop the ordering
implicit val Ordering: scala.Ordering[LanguageVersion] = {
case (LanguageVersion(Major.V1, leftMinor), LanguageVersion(Major.V1, rightMinor)) =>
Major.V1.minorVersionOrdering.compare(leftMinor, rightMinor)
case (LanguageVersion(Major.V1, _), LanguageVersion(Major.V2, _)) =>
-1
case (LanguageVersion(Major.V2, _), LanguageVersion(Major.V1, _)) =>
1
case (LanguageVersion(Major.V2, leftMinor), LanguageVersion(Major.V2, rightMinor)) =>
Major.V2.minorVersionOrdering.compare(leftMinor, rightMinor)
case (v1, v2) =>
throw new IllegalArgumentException(
s"cannot compare version ${v1.pretty} with version ${v2.pretty}"
)
}

val AllV1 = Major.V1.supportedMinorVersions.map(LanguageVersion(Major.V1, _))
Expand Down

0 comments on commit 7bc65fd

Please sign in to comment.