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 - a literal argument, or one the flow analysis knows is set; any other argument is unknown (an Optional of an unset value is unset, D-2)
  • Optional() of String → UNSET and EMPTY
  • Constructor Details

    • ConstructorStateExtractor

      public ConstructorStateExtractor(SymbolsAndScopes symbolsAndScopes, Ek9Types ek9Types, Predicate<EK9Parser.ExpressionContext> knownSet)
      Create the extractor.
      Parameters:
      knownSet - whether the flow analysis knows an expression (an Optional's argument) is set at this point
  • 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 a constructor that always makes a present but UNSET value - the no-argument constructor of a literal type (Integer(), String(), Date(), ...), whose symbol carries CONSTRUCTS_UNSET from its @Ek9Constructor(constructsUnset = true) (pinned for all 19 by ek9-lang UnsetFactsTest and 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), and recorded by the value tracker as UNSET wherever a variable is declared or assigned from one.
      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 (AlwaysSetWhenPresent, 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