E08092: empty check is always true based on data flow analysis
What went wrong
This empty check is always true based on data flow analysis. The collection or container is provably empty at this point — either because it was just constructed with no elements, or is an empty Optional/Result.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 820 (Why does EK9 reject redundant empty checks on collections?)
How to fix it
- Remove the redundant empty check and unwrap the code
- If the collection was just created with no elements, the check is unnecessary
- If this is an empty Optional, the check is unnecessary
- Check if items were intended to be added before this check
Common causes
- List/Dict created with no elements and immediately checked for empty
- Optional created with no value and checked for empty
- Defensive coding habit from languages where collections might be null
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E08092: empty check is always true based on data flow analysis
#!ek9 defines module error.e08092.bad defines function checkEmptyList() <- result as String: "has items" items <- List() of String if items empty result: "empty"
Fixed: Check a collection whose contents are not known
#!ek9 defines module error.e08092.good defines function checkEmptyList() -> items as List of String <- result as String: "has items" if items empty result: "empty"
Questions and answers
These Q&A entries show E08092 and its fix: