E08085: logical expression is always true or always false
What went wrong
This logical expression is always true or always false regardless of the operand value.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 795 (What is a logical tautology and why does EK9 reject it?)
How to fix it
- Check variable names for typos
- If always-true is intended, use 'true' directly
- If always-false is intended, use 'false' directly
- Simplify the logic to use different variables
Common causes
- Typo (same variable used twice instead of different variables)
- Refactoring error (condition was changed but negation was not removed)
- Misunderstanding of Boolean logic
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E08085: logical expression is always true or always false
#!ek9 defines module error.e08085.bad defines function checkOrNotTautology() -> isEnabled as Boolean <- result as Boolean? result: isEnabled or not isEnabled checkAndNotContradiction() -> isEnabled as Boolean <- result as Boolean? result: isEnabled and not isEnabled checkNotOrTautology() -> isEnabled as Boolean <- result as Boolean? result: not isEnabled or isEnabled checkNotAndContradiction() -> isEnabled as Boolean <- result as Boolean? result: not isEnabled and isEnabled
Fixed: Combine different conditions
#!ek9 defines module error.e08085.good defines function orDifferentVars() -> first as Boolean second as Boolean <- result as Boolean? result: first or second andNotDifferentVar() -> first as Boolean second as Boolean <- result as Boolean? result: first and not second bothNegatedDifferent() -> first as Boolean second as Boolean <- result as Boolean? result: not first or not second
Questions and answers
These Q&A entries show E08085 and its fix: