Class RedundantIsSetCheckOrError
java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.common.TypedSymbolAccess
org.ek9lang.compiler.phase5.RedundantIsSetCheckOrError
- All Implemented Interfaces:
Consumer<EK9Parser.ExpressionContext>
final class RedundantIsSetCheckOrError
extends TypedSymbolAccess
implements Consumer<EK9Parser.ExpressionContext>
Detects isSet checks that are always true or always false based on data flow analysis (E08088/E08089).
The postfix ? operator in EK9 checks if a variable is set. This checker uses the
ValueTrackingAnalyzer to determine when such checks are redundant because the variable
is provably SET (e.g., assigned from a literal, or inside a guard's true-branch) or provably
UNSET (e.g., declared with ? and never assigned).
Examples detected:
x <- "hello"; if x?— always true, string literal is always SET (E08088)if name <- getName() { if name? }— always true, guard proved SET (E08088)name as String?; if name?— always false, declared UNSET never assigned (E08089)
Inside require/assert: only the bug-class NEVER_SET case (E08089) fires.
The REDUNDANT case (E08088) is suppressed because require x? is the established
idiom for "touch this variable" since EK9 enforces capture and has no discard pattern.
Conditions inside loop bodies are suppressed because widening has not yet been applied.
-
Field Summary
Fields inherited from class RuleSupport
errorListener, symbolsAndScopes -
Constructor Summary
ConstructorsConstructorDescriptionRedundantIsSetCheckOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ValueTrackingAnalyzer valueTracker) -
Method Summary
Methods inherited from class TypedSymbolAccess
getRecordedAndTypedSymbol, isProcessingScopePure, recordATypedSymbol
-
Constructor Details
-
RedundantIsSetCheckOrError
RedundantIsSetCheckOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ValueTrackingAnalyzer valueTracker)
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceConsumer<EK9Parser.ExpressionContext>
-