Lyricdev
GitHub

LYR-MIG0304

a compare that returned an int

hint · spec 14-cli

A note of lyric fix --from-4: compare returned an int in Lyric 4 and returns ?Ordering in Lyric 5; the migration rewrites the method and the calls compared with 0, and says the others.

Explanation

Lyric 4's Ordered<T> had one method, compare(other: T): int, negative, zero or positive. Lyric 5's Ordered returns ?Ordering — null where two values have no order, as two NaN floats — and TotalOrder's totalCompare returns the total order that sort takes.

The migration writes the method's result as an Ordering: a literal -1, 0 or 1 is .Less, .Equal or .Greater, another value is compared with 0 ((a - b).compare(0)). It adds TotalOrder with a totalCompare that unwraps compare, and writes a call compared with 0 as the operator: a.compare(b) < 0 is a < b.

Said by hand: a call whose int is kept (let order = a.compare(b);) — compare the values with <, == or >, or match the Ordering.

Example

proposal[LYR-MIG0304] main.lyr:7:8: 'Version.compare' returned an int; Lyric 5's returns '?Ordering', 'null' where two values have no order, and 'totalCompare' gives the total order that 'sort' takes — where the order has no gap, 'totalCompare' alone is enough