Class GuardedAssignmentNeverAppliesOrError
- All Implemented Interfaces:
Consumer<EK9Parser.AssignmentStatementContext>
:=?) that can never apply (E08095).
:=? assigns ONLY when the target is unset. When the target is provably SET at that
point, the assignment is dead and the right-hand side is silently discarded - the code compiles
clean and does nothing. This is the same ValueTrackingAnalyzer question already asked by
RedundantIsSetCheckOrError, because :=? is an isSet check plus a conditional
assign.
The motivating case is a record property initialised to a set value and then assigned in a
constructor - which, in a pure constructor, is the only assignment form permitted
(E08100), so the mistake is easy to make and invisible:
Connections
up as Boolean: false // SET
Connections() as pure
-> isUp as Boolean
up :=? isUp // E08095 - never applies, isUp is thrown away
Only the provably-SET case is an error. A provably-UNSET target is the correct and expected
use of :=? (it is how a pure constructor initialises its fields), and UNKNOWN stays
silent so that no false positive can be raised - EK9 has no warnings, so an error must be
certain.
Conditions inside loop bodies are suppressed because widening has not yet been applied,
mirroring RedundantIsSetCheckOrError.
-
Field Summary
Fields inherited from class RuleSupport
errorListener, symbolsAndScopes -
Constructor Summary
ConstructorsConstructorDescriptionGuardedAssignmentNeverAppliesOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ValueTrackingAnalyzer valueTracker) -
Method Summary
Methods inherited from class TypedSymbolAccess
getRecordedAndTypedSymbol, isProcessingScopePure, recordATypedSymbol
-
Constructor Details
-
GuardedAssignmentNeverAppliesOrError
GuardedAssignmentNeverAppliesOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ValueTrackingAnalyzer valueTracker)
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceConsumer<EK9Parser.AssignmentStatementContext>
-