E07530: only compatible with Boolean type
What went wrong
An expression is used in a Boolean context (like condition) but its type isn't compatible with Boolean. A condition is a Boolean, or a type that promotes to Boolean with '#^' - the same rule for require, assert, if, while and a ternary.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 156 (How do I assert conditions in a test in EK9?)
- ek9 -q 305 (What is the difference between require, assert, and throw?)
How to fix it
- Use Boolean expression or conversion
- Use ? to check if set
- Use == for comparison
- For your own type with a natural true/false reading, define a '#^' (promotion) returning a Boolean
Common causes
- Using non-Boolean type as condition
- Missing conversion to Boolean
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07530: only compatible with Boolean type
#!ek9 defines module error.e07530.bad defines function checkCount() -> count as Integer //require needs a Boolean require count
Fixed: Require a Boolean, such as a set-check
#!ek9 defines module error.e07530.good defines function checkCount() -> count as Integer //'?' gives a Boolean: is count set? require count?
Questions and answers
These Q&A entries show E07530 and its fix:
Found a problem?
If EK9 reported E07530 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.