Class InheritedOperators

java.lang.Object
org.ek9lang.compiler.support.InheritedOperators

public final class InheritedOperators extends Object
THE nearest operator ABOVE a type: the declaration a type would inherit, found by walking its super CLASS chain (never its traits) and stopping at the first level that declares it. Use it - never a walk of your own, and never a look at the immediate super alone.

C2 (Steve, 2026-10-08): the generated operators and their phase-3 check once asked only the IMMEDIATE super (resolveInThisScopeOnly). A field-less Middle between Base (which declares $) and Leaf (which defaults it) then gave a false E07190, so the middle had to declare the operator itself and added an empty layer (Leaf(Middle(Base(id=1)), name=leaf)). Every generated operator now calls the NEAREST implementation above, and names its OWNER in the IR (CALL (Base)super._string()) so a back end never re-derives which class that is (Contract 19 in EK9_BACKEND_IR_CONTRACTS.md, the same shape as the close chain's CloseSteps.parentClose(IAggregateSymbol), which is built on this walk).

The walk returns the nearest declaration whatever it is - abstract, hand-written or defaulted - and the caller decides what that means (an abstract one has nothing to call). DEFENSIVE: it keeps its own visited set, because phase 3 can meet a hierarchy loop before TYPE_HIERARCHY_CHECKS has reported it.

  • Method Details

    • nearestAbove

      public static Optional<MethodSymbol> nearestAbove(IAggregateSymbol aggregate, String operatorName, ISymbol ek9Any)
      The nearest operator called operatorName declared ABOVE the aggregate, never Any's: Any declares ? $ $$ #? == <=> for every type, which says nothing about a hierarchy's data. Where a level declares several overloads, the one taking that level itself is preferred (its self-comparison or copy).
      Parameters:
      aggregate - the type whose super chain is walked (the type itself is not consulted)
      operatorName - the operator, e.g. "$"
      ek9Any - the Any type, which is never an answer
      Returns:
      the nearest declaration, if any
    • nearestAbove

      public static Optional<MethodSymbol> nearestAbove(IAggregateSymbol aggregate, Function<IAggregateSymbol, Optional<MethodSymbol>> declaredOn)
      The nearest declaration above the aggregate that declaredOn finds on a level (asked of each super class in turn, nearest first). A trait ends the walk: its operators are not inherited through the class chain.
    • allAbove

      public static List<MethodSymbol> allAbove(IAggregateSymbol aggregate, String operatorName, ISymbol ek9Any)
      EVERY operator called operatorName declared ABOVE the aggregate - each level's own overloads, nearest level first, never Any's. The same walk as nearestAbove(IAggregateSymbol, String, ISymbol), for a caller that must meet every inherited signature rather than call the nearest one: a generated :=: overrides each inherited :=:(Super) (PolymorphicCopy, Q5b).
      Parameters:
      aggregate - the type whose super chain is walked (the type itself is not consulted)
      operatorName - the operator, e.g. ":=:"
      ek9Any - the Any type, which is never an answer
      Returns:
      every declaration above, nearest level first
    • declarationSiteFor

      public static Optional<IAggregateSymbol> declarationSiteFor(IAggregateSymbol aggregate, ISymbol ek9Any)
      Where a missing operator belongs when NOTHING above the aggregate declares it (Q4, Steve 2026-10-08): the nearest super class that HAS fields of its own - the root of the data decides whether its fields are exposed (R4) - or, when no super class has fields, the topmost one (the hierarchy's root below Any). Empty only when the aggregate has no super class but Any.
    • declaredOperator

      public static Optional<MethodSymbol> declaredOperator(IAggregateSymbol aggregate, String operatorName)
      The operator called operatorName this type declares in its OWN scope, preferring the overload that takes the type itself when there are several.
    • ownerOf

      public static IAggregateSymbol ownerOf(MethodSymbol operator)
      The type that declares the operator - its OWNER, which a generated super call names.