E08086: condition is always true based on data flow analysis
What went wrong
This condition is always true based on the values assigned to variables on this code path. The compiler tracks variable assignments and can determine that this comparison will always produce the same result, making the else/default branch 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 its gate is a condition too: 'if ok <- true' always enters, and 'then ok' after such a guard is always true - the gate already required it.
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 redundant condition and its else/default branch
- If the condition is needed on some paths, restructure the logic
- Check if a variable was intended to be reassigned before this check
- Verify this isn't a copy-paste error from a similar condition
Common causes
- Variable assigned a literal and then immediately compared to that literal
- Applies to all literal types: Integer, Float, Character, String, Date, Time, DateTime, Millisecond
- Outer condition already implies the inner condition
- Redundant defensive check after a known assignment
- Refactoring left behind a condition that is no longer needed
- 'if ok <- check() then ok' — the Boolean guard already enters only when ok is true
- A Boolean guard over a value known to be true: 'if ready <- true'
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E08086: condition is always true based on data flow analysis
#!ek9 defines module error.e08086.bad defines constant MANY <- 10 SEVERAL <- 6 defines function classify() -> count as Integer <- rtn as String: "few" if count > MANY if count > SEVERAL rtn: "many" describe() <- rtn as String: "unknown" enabled <- false if not enabled rtn: "disabled"
Fixed: Test only what is not already known
#!ek9 defines module error.e08086.good defines constant MANY <- 10 defines function classify() -> count as Integer <- rtn as String: "few" if count > MANY rtn: "many" describe() -> enabled as Boolean <- rtn as String: "enabled" if not enabled rtn: "disabled"
Questions and answers
These Q&A entries show E08086 and its fix: