Class OrderingResultSources

All Implemented Interfaces:
org.antlr.v4.runtime.tree.ParseTreeListener, EK9Listener

final class OrderingResultSources extends ScopeStackConsistencyListener
The per-source half of OrderingTotality (E07188): for every method, operator and function that returns an Integer, finds where the returning variable can get its value and records the PARTIAL sources - an unset Integer(), a <=> of a partial type, a call of another callable (decided later, once every source has been walked). Holds no state of its own beyond the shared collector, so it is safe in the phase's parallel per-source walk.

THE reading of "where can the returning variable get its value": its initialiser and every plain assignment to it anywhere in the body (:, :=, :=?), and for a local variable named by a source, that variable's own initialiser and assignments. The assignments are taken without regard to order; the INITIALISER of a returning variable (the callable's, or a switch, try or loop expression's) is left out when every path gives the variable a new value - the same definite-assignment analysis as E08050, on the same branch pull-ups (IfStatementOrError, SwitchStatementOrError, TryStatementOrError, ForStatementOrError, WhileStatementOrError, reused as ConstructorFieldInitialisationListener reuses them), asked through SymbolsAndScopes.isInitialiserReplaced. So <- rtn as Integer: Integer() followed by an if/else that assigns on every arm is total; without the else it is not.

A dynamic function's result is walked the same way (its returning variable is its super function's, assigned in its body). The places a function is used AS AN ORDERING are recorded too (D91): a dynamic function declared is Comparator of T; the function a sort by uses; and a function given where a Comparator is expected - an argument for a Comparator parameter (withComparator(byPrice)), or the value of a Comparator variable or property. NOT every function phase 2 makes a Comparator (SynthesizeSuperFunction gives every pure (T, T) <- Integer function that super): a safeDivide(a, b) that is unset for a zero divisor is ordinary tri-state until something orders by it.