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.

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.