Class BooleanTruthGuard
java.lang.Object
org.ek9lang.compiler.support.BooleanTruthGuard
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 theirwhenspelling). Aswitchkeeps enter-if-set, or itscase falsecould never be reached;while,do,forandtrykeep 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'sT, whatever it is parameterised with, because the declared type isT.
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).
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanIs this pre-flow a<-or:=?(to a plain identifier) in the head of aniforelse if? Says nothing about the type - seetargetOf(EK9Parser.PreFlowStatementContext, Function, ISymbol).targetOf(EK9Parser.PreFlowStatementContext preFlow, Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol> recordedSymbol, ISymbol ek9Boolean) The target of a Boolean truth guard, if this pre-flow is one.
-
Method Details
-
targetOf
public static Optional<ISymbol> targetOf(EK9Parser.PreFlowStatementContext preFlow, Function<org.antlr.v4.runtime.tree.ParseTree, ISymbol> recordedSymbol, ISymbol ek9Boolean) The target of a Boolean truth guard, if this pre-flow is one.- Parameters:
preFlow- the pre-flow statement (may be null)recordedSymbol- how the caller reads the symbol recorded against a parse tree nodeek9Boolean- the built-in Boolean type- Returns:
- the guard's target when the truth guard applies, otherwise empty
-
isTruthGuardPosition
Is this pre-flow a<-or:=?(to a plain identifier) in the head of aniforelse if? Says nothing about the type - seetargetOf(EK9Parser.PreFlowStatementContext, Function, ISymbol).
-