Why does EK9 flag checking empty on a freshly constructed list?
← Code Quality · Ref: Q865
EK9 uses data flow analysis to detect redundant empty checks. A freshly created collection is always empty, so checking 'if items empty' immediately after creation is a tautology — the condition is always true.
REDUNDANT (E08092)
items <- List() of String if items empty // ALWAYS true — nothing was added result: "nothing here"
VALID CHECK
items <- List() of String items += "hello" if items empty // valid — state changed since creation result: "nothing here"
Adding items between creation and the empty check makes the check meaningful because the collection state is no longer provably empty.
See Q820 for redundant empty check overview. See Q310 for code quality.
Example
defines module qa.quality.redundant.empty defines function checkEmptiness() -> greeting as String <- result as String: String() items <- List() of String items += greeting if items empty result: "nothing here" else result: "has content" defines program RedundantEmptyDemo() stdout <- Stdout() outcome <- checkEmptiness("hello") stdout.println(`Result: ${outcome}`)
Common mistakes
E08092 — Without adding any items, the list is provably empty. Checking 'if items empty' is always true — the compiler detects this tautology. Add items before checking. See ek9 -h E08092 for details.
Incorrect:
if items empty
Correct:
items += greeting if items empty
Other ways to ask this
- What triggers E08092 REDUNDANT_EMPTY_CHECK?
- Why is checking empty right after creating a list redundant?
- How does EK9 detect tautological empty checks?
Coming from another language?
Java: no detection — isEmpty() on new ArrayList compiles silently. Python: no detection. Rust: no detection. Go: no detection. EK9: compile-time error for provably redundant empty checks via data flow analysis.
Keywords: empty, flow, list, collection, redundant, E08092, data, tautology