Class SafeAccessConjuncts
java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.common.TypedSymbolAccess
org.ek9lang.compiler.phase5.AbstractSafeSymbolMarker
org.ek9lang.compiler.phase5.SafeAccessConjuncts
THE conjunct walk for Optional/Result/Iterator safe access (Steve, 2026-10-07, decision Q3) - use it, never
re-derive a variant. A condition is flattened into its TOP-LEVEL
and conjuncts (the root and
chain, parenthesised and groups included); each conjunct of the form x? (or the named checks
r.isOk(), r.isError(), it.hasNext()) proves its subject set:
- in the body the condition guards (
markProven(EK9Parser.ExpressionContext, IScope)), whatever the other conjuncts are -r? and (count < limit)makesr.get()safe in the body; - inside the expression itself, for a LATER conjunct only, left to right (
isProvenEarlier(ParseTree, ISymbol, CommonValues)) -andshort-circuits, soo? and o.get() > 0is safe ando.get() > 0 and o?is not.
? under or, xor, not, a ternary or a call argument proves
nothing, so (o? and x) or (o? and y) and not not o? make nothing safe.
This replaced the earlier rule that the WHOLE condition had to be a "simple" and of checks.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final recordOne fact a conjunct proves:access(ok/error/get/next) onsymbolis safe. -
Field Summary
Fields inherited from class AbstractSafeSymbolMarker
containersFields inherited from class RuleSupport
errorListener, symbolsAndScopes -
Constructor Summary
ConstructorsConstructorDescriptionSafeAccessConjuncts(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ContainerChangedBetween containerChangedBetween) -
Method Summary
Modifier and TypeMethodDescription(package private) booleanisProvenEarlier(org.antlr.v4.runtime.tree.ParseTree accessSite, ISymbol symbol, CommonValues access) True whenaccessonsymbolataccessSiteis protected by an EARLIER conjunct of an enclosingandevaluated as part of the same expression, and nothing evaluated between that conjunct and the access may change the container (name? and forget(name) and name.get() > 0is not protected -ContainerChangedBetween).(package private) voidmarkProven(EK9Parser.ExpressionContext condition, IScope scopeMadeSafe) Mark everything the top-level conjuncts ofconditionprove as safe inscopeMadeSafe- unless the rest of the condition, after the proving conjunct, may change the container (if name? and forget(name)): the body runs after all of it (ContainerChangedBetween).(package private) booleanprovesEveryAccess(EK9Parser.ExpressionContext condition, ISymbol symbol) Doesconditionprove EVERY accesssymbol's container guards (get()of an Optional,next()of an Iterator; a Result'sok()anderror()are never both proven), with nothing after the proving conjunct that may change it? The trailing condition of ado/whilethat does is checked before every later pass of its body, so the body's own changes do not reach those passes.Methods inherited from class AbstractSafeSymbolMarker
assessIsSetCallMethods inherited from class TypedSymbolAccess
emitTypeNotResolvedError, getRecordedAndTypedSymbol, isAlreadyInError, isProcessingScopePure, isPureReassignmentDisallowed, recordATypedSymbol
-
Constructor Details
-
SafeAccessConjuncts
SafeAccessConjuncts(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ContainerChangedBetween containerChangedBetween)
-
-
Method Details
-
markProven
Mark everything the top-level conjuncts ofconditionprove as safe inscopeMadeSafe- unless the rest of the condition, after the proving conjunct, may change the container (if name? and forget(name)): the body runs after all of it (ContainerChangedBetween). -
provesEveryAccess
Doesconditionprove EVERY accesssymbol's container guards (get()of an Optional,next()of an Iterator; a Result'sok()anderror()are never both proven), with nothing after the proving conjunct that may change it? The trailing condition of ado/whilethat does is checked before every later pass of its body, so the body's own changes do not reach those passes. -
isProvenEarlier
boolean isProvenEarlier(org.antlr.v4.runtime.tree.ParseTree accessSite, ISymbol symbol, CommonValues access) True whenaccessonsymbolataccessSiteis protected by an EARLIER conjunct of an enclosingandevaluated as part of the same expression, and nothing evaluated between that conjunct and the access may change the container (name? and forget(name) and name.get() > 0is not protected -ContainerChangedBetween).
-