Class SelfComparisonOrError
java.lang.Object
org.ek9lang.compiler.common.RuleSupport
org.ek9lang.compiler.common.TypedSymbolAccess
org.ek9lang.compiler.phase5.SelfComparisonOrError
- All Implemented Interfaces:
Consumer<EK9Parser.ExpressionContext>
final class SelfComparisonOrError
extends TypedSymbolAccess
implements Consumer<EK9Parser.ExpressionContext>
Detects self-comparison expressions where both sides resolve to the same symbol (E08081).
Expressions like value == value (always true), value <> value (always false),
or value <=> value (always 0) are pointless and indicate copy-paste errors or logic bugs.
Only comparison operators are flagged. Arithmetic operators like a + a (valid doubling)
and logical operators like a and a are not flagged.
Research basis: Microsoft study (2011) found self-comparison bugs in 3% of copy-paste errors. GCC, Clang, and IntelliJ all flag self-comparison as a warning.
-
Field Summary
Fields inherited from class RuleSupport
errorListener, symbolsAndScopes -
Constructor Summary
ConstructorsConstructorDescriptionSelfComparisonOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) -
Method Summary
Methods inherited from class TypedSymbolAccess
getRecordedAndTypedSymbol, isProcessingScopePure, recordATypedSymbol
-
Constructor Details
-
SelfComparisonOrError
SelfComparisonOrError(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener)
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceConsumer<EK9Parser.ExpressionContext>
-