Class ConstantComparisonOrError
java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.common.TypedSymbolAccess
org.ek9lang.compiler.phase5.ConstantComparisonOrError
- All Implemented Interfaces:
Consumer<EK9Parser.ExpressionContext>
final class ConstantComparisonOrError
extends TypedSymbolAccess
implements Consumer<EK9Parser.ExpressionContext>
Detects comparisons where both operands are literals (E08082).
Expressions like 1 == 1 (always true), "hello" <> "world" (always true),
or true == false (always false) have predetermined results and indicate logic errors,
dead code, or copy-paste mistakes.
Exemptions: comparisons inside require, assert, and constrain
statements are not flagged, as these are test assertions where literal comparisons
serve a documentation purpose.
Only comparison operators are checked. Arithmetic between literals is valid constant folding and is handled separately by the compiler.
-
Field Summary
Fields inherited from class RuleSupport
errorListener, symbolsAndScopes -
Constructor Summary
ConstructorsConstructorDescriptionConstantComparisonOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) -
Method Summary
Methods inherited from class TypedSymbolAccess
getRecordedAndTypedSymbol, isProcessingScopePure, recordATypedSymbol
-
Constructor Details
-
ConstantComparisonOrError
ConstantComparisonOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener)
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceConsumer<EK9Parser.ExpressionContext>
-