Class ConstrainedDelegation

java.lang.Object
org.ek9lang.compiler.phase7.ConstrainedDelegation

final class ConstrainedDelegation extends Object
THE delegation bodies of a constrained type (DFN-3): every method and operator cloned from the base forwards to the base value held in _delegate, re-wrapping a base result as the constrained type, and a mutation re-validates the delegate afterwards; #^ (and _base()) hand back a COPY of the delegate.
  • Constructor Details

  • Method Details

    • processDelegationMethod

      void processDelegationMethod(OperationInstr operation)
      Generate delegation method/operator body.
    • processPromote

      void processPromote(OperationInstr operation, String scopeName)
      Promote (#^) - and the synthesised _base(), scoped as scopeName - returns a fresh COPY of the delegate, never the delegate field reference.

      The constrained type is a wrapper whose delegate field is its private, constraint-checked state. Returning that reference directly would alias it: a later in-place mutation of the promoted base value (base types like Integer are mutable) would silently corrupt the constrained value and bypass its constraint invariant. So we construct an independent base instance (new Base(delegate)) and return that. See ConstrainedTypeInstrs.copyBaseValue(List, String, DebugInfo).