Class RedundantEmptyCheckOrError
java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.common.TypedSymbolAccess
org.ek9lang.compiler.phase5.RedundantEmptyCheckOrError
- All Implemented Interfaces:
Consumer<EK9Parser.ExpressionContext>
final class RedundantEmptyCheckOrError
extends TypedSymbolAccess
implements Consumer<EK9Parser.ExpressionContext>
Detects empty checks that are always true or always false based on data flow analysis (E08092/E08093).
The empty keyword in EK9 checks if a collection or container has no elements.
This checker uses the ValueTrackingAnalyzer to determine when such checks are redundant
because the container is provably EMPTY (e.g., just constructed with no elements) or provably
NON-EMPTY (e.g., constructed from a literal with elements).
Examples detected:
items <- List() of String; if items empty— always true (E08092)numbers <- [1, 2, 3]; if numbers empty— always false (E08093)present <- Optional("hello"); if present empty— always false (E08093)absent <- Optional() of String; if absent empty— always true (E08092)
Also handles negated form: if items not empty swaps the error codes.
Exemptions: conditions inside require, assert, and constrain
statements are not flagged. Conditions inside loop bodies are also suppressed because
widening has not yet been applied.
-
Field Summary
Fields inherited from class RuleSupport
errorListener, symbolsAndScopes -
Constructor Summary
ConstructorsConstructorDescriptionRedundantEmptyCheckOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ValueTrackingAnalyzer valueTracker) -
Method Summary
Methods inherited from class TypedSymbolAccess
getRecordedAndTypedSymbol, isProcessingScopePure, recordATypedSymbol
-
Constructor Details
-
RedundantEmptyCheckOrError
RedundantEmptyCheckOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener, ValueTrackingAnalyzer valueTracker)
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceConsumer<EK9Parser.ExpressionContext>
-