Class Sameness

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

public final class Sameness extends Object
THE vocabulary of B18 - "a type defines sameness once" - call this, do not re-derive it.

A type's SAMENESS is its <=> (an ordered type) or its == (an equatable-only type), chosen by the author. Every other comparison with the type itself (== <> < <= > >=) is generated from it, #? goes with it, and it is declared once per hierarchy, concretely.

🔑 SELF means "any type this type is assignable to" - itself, a super, a trait, Any. A ==(Any) or an override ==(Base) compares the type with itself as surely as ==(Self) does; treating those as "other types" left the disagreement B18 removes reachable (Fable review F1). Operators taking a genuinely unrelated type (==(Integer), <(Date)) are not self-comparisons.

  • Field Details

    • SAMENESS_FAMILY

      public static final Set<String> SAMENESS_FAMILY
      The operators whose presence the type's sameness decides - never added by the bare default operator by name in phase 1, only once types are known (OperationFactory.completeSameness).
  • Method Details

    • isSelfComparison

      public static boolean isSelfComparison(IAggregateSymbol owner, MethodSymbol operator)
      True for an operator taking exactly one argument of a type the owner is assignable to.
    • isSamenessOperator

      public static boolean isSamenessOperator(IAggregateSymbol owner, MethodSymbol operator)
      True for a <=> or == comparing the owner with itself - a declaration of its sameness.
    • isDerivedComparison

      public static boolean isDerivedComparison(IAggregateSymbol owner, MethodSymbol operator)
      True for a <> < <= > >= comparing the owner with itself - always generated from the sameness, never written.
    • isHashCode

      public static boolean isHashCode(MethodSymbol operator)
      True for the zero-argument #?.
    • isHandWritten

      public static boolean isHandWritten(MethodSymbol operator)
      True when the developer wrote the operator's body (not default operator).
    • isExplicitlyDefaulted

      public static boolean isExplicitlyDefaulted(MethodSymbol operator)
      True for an explicit default operator X, as opposed to one added by the bare default operator.
    • isGenerated

      public static boolean isGenerated(MethodSymbol operator)
      True for a comparison generated from the type's sameness (never written or requested).
    • inheritedSameness

      public static Optional<MethodSymbol> inheritedSameness(IAggregateSymbol aggregate, ISymbol ek9Any)
      The concrete sameness this type INHERITS - from its super chain (stopping before Any) or any of its traits (its own, a super's, a trait's trait) - if any. Such a type may not declare sameness or #? of its own: the hierarchy's sameness is sealed where it is declared.

      DEFENSIVE: this runs at the end of EXPLICIT_TYPE_SYMBOL_DEFINITION, before TYPE_HIERARCHY_CHECKS reports a circular hierarchy, so it walks with its own visited set rather than getAllTraits() (which recurses without one and overflowed on a loop). A broken hierarchy must neither error nor crash here.