Issue #1873: Ordering has Rust’s methods: then, then_with, reverse, is_* (ADR-traits-order-v1 D7-D9)

Open and answer this issue on GitHub.

ready, bugs, queued · opened 2026-11-16 · updated 2026-11-29 · 0 comments

Filed by the driver from the Found: of the run of issue-1618 (#1618) (owner, 2026-11-06).

Found

Ordering has no methods: rows.sort_by fn (a, b) { b.1.compare(a.1).then(a.0.compare(b.0)) } draws NK1171 “Ordering has no method called then” (std.contracts lists no Ordering:: entry); benches/game/k-nucleotide/speed.nika sorts twice with two stable sort_by calls instead of one combined comparator.

Reproduced on develop 588b5330 (2026-11-29):

fn main() throws {
    let mut rows: Vec[(String, i64)] = [("b", 2), ("a", 2), ("c", 1)]
    rows.sort_by fn (a, b) { b.1.compare(a.1).then(a.0.compare(b.0)) }
    println(f"{rows[0].0}{rows[1].0}{rows[2].0}")
}
error[NK1171]: `Ordering` has no method called `then`.

Decision (supervisor, 2026-11-29)

Decided under docs/supervisor.md, Language decisions, as obvious: a std counterpart of a Rust call that nobody pays for who does not use it (precedent ADR-384). ADR-341 §6 had left the methods as “library entries, asked when a program needs them”, and a program needs them now. Ordering is already Rust’s std::cmp::Ordering in the generated code (D1), so the methods lower one to one.

The decision first landed as a record of its own (ADR-ordering-v1, 78512084). The methods belong to ADR-341’s topic (Eq, Ord, Ordering), so by ADR-decision-records-v2 D2/D4 both were consolidated into one record (b3b6f63d): ADR-341 D1-D6 keep their numbers, the methods are D7-D9. Both earlier records are in docs/history/adr/.

To build

  1. std.contracts: fn."Ordering::then" ((self: Ordering, other: Ordering) -> Ordering, sync = true, panics = false), fn."Ordering::then_with" ((self: Ordering, f: fn() -> Ordering) -> Ordering, sync = "sync(f)" as Entry::or_insert_with), fn."Ordering::reverse", and is_eq, is_ne, is_lt, is_gt, is_le, is_ge (-> bool, sync = true, panics = false), each lowered to std::cmp::Ordering’s method of the same name (ADR-traits-order-v1 D9).
  2. Test tests/compiler/tests/ordering_then_sorts_by_two_keys.nika: the probe above prints abc.
  3. Test tests/compiler/tests/ordering_methods.nika: then_with runs its lambda only for Equal (a counter it bumps), reverse on all three, and each is_* on all three variants; .stdout beside it.
  4. Test: a program that declares its own enum Ordering keeps its own methods (D1, Part I 4.7).
  5. benches/game/k-nucleotide/speed.nika: one sort_by with .then(...) in place of the two stable sorts; same output.
  6. ADR index: Built column of traits-order-v1 from partly: D7-D9 (#1873) to yes.

Done when

The probe prints abc, the tests of steps 2-4 are green in nikaia test, and speed.nika sorts once with the same output.

Back to Open Issues