E08084: comparing a Boolean with true/false is redundant
What went wrong
Comparing a Boolean expression with true or false is redundant. Use the expression directly.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 639 (Should I compare Boolean values with == true or == false?)
- ek9 -q 558 (What are tautological conditions and how do I fix them?)
How to fix it
- For '== true' or '<> false': use the expression directly
- For '== false' or '<> true': use 'not expression'
- Comparing two Boolean variables is valid
Common causes
- Habit from languages where conditions are not inherently Boolean
- Overly explicit coding style
- 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 E08084: comparing a Boolean with true/false is redundant
#!ek9 defines module error.e08084.bad defines function checkEqualTrue() -> ready as Boolean <- result as Boolean? result: ready == true checkNotEqualTrue() -> ready as Boolean <- result as Boolean? result: ready <> true checkEqualFalse() -> ready as Boolean <- result as Boolean? result: ready == false checkNotEqualFalse() -> ready as Boolean <- result as Boolean? result: ready <> false checkReversedTrueEqual() -> ready as Boolean <- result as Boolean? result: true == ready
Fixed: Use the Boolean directly, or with not
#!ek9 defines module error.e08084.good defines function compareTwoBooleans() -> first as Boolean second as Boolean <- result as Boolean? result: first == second useBooleanDirectly() -> ready as Boolean <- result as Boolean? result: ready useNegatedBoolean() -> ready as Boolean <- result as Boolean? result: not ready
Questions and answers
These Q&A entries show E08084 and its fix: