Class OrderingTotality

java.lang.Object
org.ek9lang.compiler.phase5.OrderingTotality

final class OrderingTotality extends Object
THE compile-time check that a hand-written <=> orders every two SET values of its type (E07188; Steve, 2026-10-21, sameness stock-take 4.4: "This is a closed system and we already have code that detects the subtypes").

The rule. A hand-written <=> is PARTIAL when the Integer it returns can come from a source that is unset for two set values. The sources of the returning variable are its initialiser and every assignment to it (and, through a local variable, that variable's own sources); a source is partial when it is

  • an UNSET construction - Integer() - a result a <=> names by its own choice (... else Integer());
  • a <=> of a type whose <=> is partial (PartialOrdering): Money (one currency) or Dimension (one suffix), declared on the type; a type whose values can be of different run-time types under a per-type sameness (an open or abstract type - D24, extended 2026-10-27); or a user type's hand-written <=> that is itself partial (the sub-type analysis: the call resolves to the very <=> that runs); a DEFAULTED <=> is never a source here - over a partial field it is withdrawn (OrderingAvailability.orderingSurvives(MethodSymbol, ISymbol)) and a use of it is E07620;
  • a call of a method, operator or function whose own Integer result comes from such a source (followed through the callable's own sources, to any depth; a cycle is assumed total).

A path that leaves the result unassigned is not asked here: E08050 already refuses it for a returning variable with no initialiser. The check is flow-INSENSITIVE on purpose (no second flow engine, simple to explain): a partial source guarded by a test is still reported - write the result so that no source can be unset.

Collected per source (OrderingResultSources, parallel), decided once every source has been walked: a callee in another file is read from here, not from its parse tree; the verdicts are one least fixed point over every recorded callable (partialReasons()). A <=> over a bare generic T - in the generic's own <=>, or reached from it through a call - is judged where T is given its type instead (phase4/ParameterisedTypeOrError, D89, D91 step 4). Residual (documented, runtime backstop kept): a field's <=> that is an Optional or Dict entry (a DictEntry keyed by Money - runtimeFuzz d52SortPartialOrdering), and a hand-written ? that calls a value set while a field is unset.

A comparator is an ordering too (D91, Steve 2026-10-30): the same rule, E07188, for a function where it is used AS an ordering - a dynamic function declared is Comparator of T where it is declared (its purpose; so every delegate of that type, and PriorityQueue.withComparator), and any other function where sort by uses it. Anywhere else an Integer result that can be unset is ordinary tri-state and is not reported.

  • Constructor Details

    • OrderingTotality

      OrderingTotality()
  • Method Details

    • record

      void record(ISymbol callable, List<OrderingTotality.Finding> found)
      Record the partial sources of one callable's Integer result; nothing is recorded for a total one.
    • recordComparator

      void recordComparator(IToken token, FunctionSymbol function, String declaredAs)
      A dynamic function declared is Comparator of T: an ordering, judged where it is declared.
    • recordComparatorUse

      void recordComparatorUse(IToken token, String user, FunctionSymbol function)
      A function used as an ordering (sort by f, given for a Comparator): judged at that use.
    • check

      void check(Function<IToken, ErrorListener> listenerFor)
      Report every hand-written <=> (a type's own sameness), every declared Comparator and every use of a function as an ordering whose result can be partial.
      Parameters:
      listenerFor - the error listener of the source a token belongs to