apple / pkl

A configuration as code language with rich validation and tooling.
https://pkl-lang.org
Apache License 2.0
10.38k stars 280 forks source link

pkl:semver sortorder (isLessThan) failure? #772

Closed kuehl closed 2 weeks ago

kuehl commented 2 weeks ago

hello,

sorting by using semver's isLessThan() produces unexpected results.

pkl --version
Pkl 0.26.3 (Linux 5.15.0-1057-aws, native)

a simple test_semver.pkl

amends "pkl:test"
import "pkl:semver"
facts {
  ["shall_be_true"] {
    semver.Version("6.0.417").isLessThan(semver.Version("8.0.100"))
  }
  ["shall_be_false"] {
    semver.Version("6.0.417").isGreaterThan(semver.Version("8.0.100"))
  }
}
pkl test test_semver.pkl
  shall_be_true ✅
  shall_be_false ✅

doesn't fail?

i think semver's isLessThan

...
function isLessThan(other: Version): Boolean =
    major < other.major ||
    minor < other.minor ||
    patch < other.patch
...

should be something like

...
function isLessThan(other: Version): Boolean =
    major < other.major ||
    major == other.major && minor < other.minor ||
    major == other.major && minor == other.minor && patch < other.patch
...

?

bioball commented 2 weeks ago

You're totally right! This is incorrect; thanks for pointing this out.