E08087: condition is always false based on data flow analysis
What went wrong
This condition is always false based on the values assigned to variables on this code path. The compiler tracks variable assignments and can determine that this comparison will never be satisfied, making the if-body unreachable dead code.
A guard over a Boolean is a truth guard: in an 'if' / 'else if', 'if ok <- check()' enters only when ok is SET AND TRUE. So 'if ok <- false' (or 'if ok <- Boolean()', which is unset) never enters, and 'then not ok' after such a guard is always false.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 796 (Why does EK9 reject comparisons against variables with kn...)
How to fix it
- Remove the unreachable condition and its body
- Check if the variable should have been assigned a different value
- Verify this isn't a copy-paste error with an incorrect comparison value
- Check if a reassignment is missing between the assignment and the condition
Common causes
- Variable assigned a constant but compared to a different constant
- Applies to all literal types: Integer, Float, Character, String, Date, Time, DateTime, Millisecond
- Contradictory conditions (e.g., checking x < 0 after throwing on x < 0)
- Refactoring changed an assignment but not the corresponding condition
- Dead switch case where an earlier case always matches
- 'if ok <- false' or 'then not ok' after 'if ok <- check()' — a Boolean guard enters only when ok is true
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E08087: condition is always false based on data flow analysis
#!ek9 defines module error.e08087.bad defines constant MANY <- 10 FEW <- 3 defines function classify() -> count as Integer <- rtn as String: "some" if count > MANY and count < FEW rtn: "impossible" describe() <- rtn as String: "unknown" status <- "ready" if status == "error" rtn: "failed"
Fixed: Test a value that can vary
#!ek9 defines module error.e08087.good defines constant MANY <- 10 FEW <- 3 defines function classify() -> count as Integer <- rtn as String: "some" if count > MANY or count < FEW rtn: "outside" describe() -> status as String <- rtn as String: "unknown" if status == "error" rtn: "failed"
Questions and answers
These Q&A entries show E08087 and its fix: