E08093: empty check is always false based on data flow analysis

Category: E08xxx Pre-IR checks (flow analysis) · Reported in phase: PRE_IR_CHECKS · Classification: NEVER_EMPTY_CHECK · All error codes

What went wrong

This empty check is always false based on data flow analysis. The collection or container is provably non-empty at this point — either because it was constructed with elements, or is an Optional with a value.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 825 (Why does EK9 reject 'not empty' on a freshly created coll...)

How to fix it

  1. Remove the dead code inside the empty check
  2. If the collection was constructed with elements, it cannot be empty
  3. If this is an Optional with a value, it cannot be empty
  4. Verify this is not a copy-paste error from a different variable

Common causes

  • List/Dict created from a literal and immediately checked for empty
  • Optional created with a value and checked for empty
  • Refactoring changed construction but left the empty check
  • Misunderstanding: empty means "no elements", not "unset" for collections

See also

  • E08092: empty check always true (container provably empty)
  • E08089: isSet check always false (variable provably UNSET)
  • E08087: condition always false (comparison-based tautology)

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E08093: empty check is always false based on data flow analysis

#!ek9
defines module error.e08093.bad

  defines function

    checkListLiteral()
      <- result as String: "has items"
      numbers <- [1, 2, 3]
      if numbers empty
        result: "empty"

Fixed: A literal list is never empty: use it, check only what may be empty

#!ek9
defines module error.e08093.good

  defines function

    checkListLiteral()
      <- result as String: "has items"
      numbers <- [1, 2, 3]
      result: `has ${length numbers} items`

    checkSupplied()
      -> numbers as List of Integer
      <- result as String: "has items"
      if numbers empty
        result: "empty"

Questions and answers

These Q&A entries show E08093 and its fix: