Class GuardVariableReadWhereUnsetOrError

java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.phase5.GuardVariableReadWhereUnsetOrError
All Implemented Interfaces:
Consumer<EK9Parser.IfStatementContext>

final class GuardVariableReadWhereUnsetOrError extends RuleSupport implements Consumer<EK9Parser.IfStatementContext>
E08270 (Steve, 2026-10-07, Q4): reading a <- guard's variable in a LATER else if / else block of the same if chain, before anything assigns it there.

if v <- f() declares v for the whole chain, and every later block runs only because v was unset - so a read there can only find nothing. Only a guard that is the WHOLE condition is provably unset: with a then/with condition a later block also runs when v was set and the condition false, and a Boolean truth guard (BooleanTruthGuard) also skips a set false. Neither is reported.

A WRITE stays legal - :=, =, :, :=? give v a value - and a read after it is fine. "After" is source order within the later block (its pre-flow and condition included): an assignment anywhere earlier in the block, even in a nested branch, means v is no longer PROVABLY unset, and a read inside a loop that also assigns v may see the assignment from an earlier pass. Every other use of v - a mutating operator such as += or :=:, a method call, an argument, a capture - is a read.