Package org.ek9lang.compiler.phase1
Class ValidPreFlowAndReturnOrError
java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.phase1.ValidPreFlowAndReturnOrError
- All Implemented Interfaces:
BiConsumer<EK9Parser.PreFlowStatementContext,
EK9Parser.ReturningParamContext>
class ValidPreFlowAndReturnOrError
extends RuleSupport
implements BiConsumer<EK9Parser.PreFlowStatementContext,EK9Parser.ReturningParamContext>
Checks that if a return is used (i.e. as parent context is part of an expression), then if a preflow is employed
that the preflow is NOT a guard.
The reason for this is to prevent the lhs of an expression resulting in being uninitialized should the 'guard'
trigger the prevention of the whole expression on the rhs not being executed.
So, for normal statements using while, for, try, switch the guard can be useful and stop lots of checks and wasted
processing. But if this same approach is allowed with the expression form, it means that we have a dandling and
uninitialised lhs variable. This is a bigger problem in a 'pure' scope block and we always drive to ensure variables
are only assigned to once (except for returns and other very small cases (loop variables etc).
-
Field Summary
Fields inherited from class org.ek9lang.compiler.common.RuleSupport
errorListener, symbolsAndScopes
-
Constructor Summary
ConstructorDescriptionValidPreFlowAndReturnOrError
(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(EK9Parser.PreFlowStatementContext preFlowStatementContext, EK9Parser.ReturningParamContext returningParamContext) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.function.BiConsumer
andThen
-
Constructor Details
-
ValidPreFlowAndReturnOrError
ValidPreFlowAndReturnOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener)
-
-
Method Details
-
accept
public void accept(EK9Parser.PreFlowStatementContext preFlowStatementContext, EK9Parser.ReturningParamContext returningParamContext) - Specified by:
accept
in interfaceBiConsumer<EK9Parser.PreFlowStatementContext,
EK9Parser.ReturningParamContext>
-