Class BooleanTruthGuard

java.lang.Object
org.ek9lang.compiler.support.BooleanTruthGuard
All Implemented Interfaces:
BiFunction<EK9Parser.PreFlowStatementContext, ISymbol, Optional<ISymbol>>

public final class BooleanTruthGuard extends Object implements BiFunction<EK9Parser.PreFlowStatementContext, ISymbol, Optional<ISymbol>>
THE Boolean truth guard rule (Steve, 2026-10-07, decision D9.2) - use this, do not re-derive it.

An if or else if head whose pre-flow is a declaration guard (<-) or an assign-if-unset (:=?), and whose target's DECLARED type is exactly Boolean, enters only when the target is SET AND TRUE. Every other guard enters when its target is set. So if ok <- check() skips the body when check() returns false, exactly as a reader expects; before this rule a set false entered it.

Deliberately narrow:

  • Only if / else if (and their when spelling). A switch keeps enter-if-set, or its case false could never be reached; while, do, for and try keep enter-if-set too.
  • Only <- and :=?. A := head is blind (no gate at all).
  • Only a target whose type IS Boolean (by symbol identity, isExactSameType). A type that merely promotes to Boolean (#^) keeps enter-if-set; so does a generic's T, whatever it is parameterised with, because the declared type is T.

Phase 7 adds the _true() test to the guard's gate (GuardedConditionEvaluator); phase 5 narrows the target to true inside the body and does not narrow it to unset on the skip path (it may be false).

It answers with the guard's TARGET, given the pre-flow and the built-in Boolean type; the caller says, when it makes one, how it reads the symbol recorded against a parse tree node.

  • Constructor Details

    • BooleanTruthGuard

      public BooleanTruthGuard(Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol> recordedSymbol)
      The rule, reading recorded symbols the caller's way.
      Parameters:
      recordedSymbol - how the caller reads the symbol recorded against a parse tree node
  • Method Details