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.
Only comparison operators are checked. Arithmetic between literals is valid constant folding and is handled separately by the compiler.
Comparisons inside require/assert are exempt — test code legitimately uses
patterns like assert 10 - 3 == 7 to verify runtime arithmetic and operator semantics.
The compiler can prove these statically, but the developer's intent is to test execution.
-
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>
-