Class 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.

Inside require/assert: only the bug-class NEVER_EMPTY case (E08093) fires. The REDUNDANT case (E08092) is suppressed because require list empty on a provably-empty list is the same scaffolding pattern as require x?.

Conditions inside loop bodies are suppressed because widening has not yet been applied.