Class PreFlowCanSkipBody

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

public final class PreFlowCanSkipBody extends Object
THE single definition of "can this control-flow pre-flow skip the construct body?".

A pre-flow (the head of an if/while/do/for/switch/try) is a body-skipping guard iff its operator performs an isSet check that can skip the body:

A plain :=/= assignment (EK9Parser.ASSIGN/EK9Parser.ASSIGN2) is NOT a guard - the body always runs. A null pre-flow is not a guard.

This is the SOLE authority, consumed by BOTH phase 5 and phase 7, so the two phases can never drift on what a guard is (that drift was the root cause of a null-safety bug where an expression-form return declared as T? could be left as a raw Java null on the skip path):

  • Phase 5 uses it to decide when an expression-form return MUST be initialised (RETURN_NOT_ALWAYS_INITIALISED / E08050) - a skippable body means the return's initial value is the result on the skip path, so an uninitialised <- rtn as T? is an error.
  • Phase 7 uses it (via GuardedConditionEvaluator.requiresGuardCheck) to decide whether to emit a guard entry-check that gates the body.

Do NOT re-derive a variant of this classification - call this.

  • Method Details

    • canSkipBody

      public static boolean canSkipBody(EK9Parser.PreFlowStatementContext preFlow)
      True iff this pre-flow is a body-skipping guard (<-, ?=, :=?).
      Parameters:
      preFlow - the pre-flow statement context (may be null)
      Returns:
      true if the pre-flow can skip the construct body
    • operatorCanSkipBody

      public static boolean operatorCanSkipBody(Integer operatorType)
      True iff this pre-flow operator token type is a body-skipping guard operator. The token-level entry point so phase 7 (which already resolves the operator type) can share the exact same classification without re-deriving it.
      Parameters:
      operatorType - the pre-flow operator token type (may be null)
      Returns:
      true if the operator can skip the construct body