Class ConstructorStateExtractor

java.lang.Object
org.ek9lang.compiler.phase5.flow.ConstructorStateExtractor

public final class ConstructorStateExtractor extends Object
Extracts collection/container state information from constructor calls and literal expressions.

Detects constructor calls on built-in collection and container types (List, Dict, Optional) and literal expressions ([...], {...}) to determine their initial SET/UNSET and EMPTY/NON-EMPTY state at construction time.

Detection rules:

  • [1, 2, 3] (list literal) → SET and NON-EMPTY
  • {"key": 1} (dict literal) → SET and NON-EMPTY
  • List() of String → SET and EMPTY
  • Dict() of (String, Integer) → SET and EMPTY
  • Optional("hello") → SET and NON-EMPTY
  • Optional() of String → UNSET and EMPTY
  • Constructor Details

  • Method Details

    • extractFromAssignment

      public CollectionStateValue extractFromAssignment(EK9Parser.AssignmentExpressionContext assignExpr)
      Extract a CollectionStateValue from an assignment expression if it is a collection/container constructor or literal.
      Parameters:
      assignExpr - the assignment expression to examine
      Returns:
      a CollectionStateValue if a known constructor pattern is detected, null otherwise
    • extractFromExpression

      public CollectionStateValue extractFromExpression(EK9Parser.ExpressionContext expr)
      Extract a CollectionStateValue from an expression if it is a collection/container constructor or literal.
      Parameters:
      expr - the expression to examine
      Returns:
      a CollectionStateValue if a known pattern is detected, null otherwise
    • isUnsetLiteralTypeConstruction

      public boolean isUnsetLiteralTypeConstruction(EK9Parser.AssignmentExpressionContext assignExpr)
      Is this assignment's right-hand side the no-argument constructor of a literal type (Ek9LiteralTypes.LITERAL_TYPE_NAMES: Integer(), String(), Date(), ...)? Every one of those makes a present but UNSET value - the value a literal would give it is exactly what is missing (measured for all 19, pinned by runtimeFuzz literalTypeNoArgUnset). A user type's constructor never counts here: its ? is its own to define (E07235) - the one user-type fact that IS provable, a field-less type set by being present, is isAlwaysSetConstruction(EK9Parser.AssignmentExpressionContext). Read by the guard-gate check (D7); the value tracker does not record it in general.
      Parameters:
      assignExpr - the assignment expression to examine
      Returns:
      true when the value is provably unset
    • isAlwaysSetConstruction

      public boolean isAlwaysSetConstruction(EK9Parser.AssignmentExpressionContext assignExpr)
      Is this assignment's right-hand side a construction of a type with no fields, counting inherited ones, whose '?' is the synthesised one (FieldlessIsSet.alwaysSetWhenPresent(IAggregateSymbol), Q-COMPONENT-?)? Such a value is set whenever it is present, so it is provably SET (F3, Steve 2026-10-07) - the counterpart of isUnsetLiteralTypeConstruction(EK9Parser.AssignmentExpressionContext). Any constructor of the type counts; a call that is not a constructor (a function returning the type, which may return a sub-type with its own '?') never does.
      Parameters:
      assignExpr - the assignment expression to examine
      Returns:
      true when the value is provably set