constant_condition
Finds an if or while whose condition the compiler shows is always true or false.
Category suspicious, warn by default.
#import "Basic";
check :: (count: s64) {
if count > 10 {
if count < 5 {
print("never\n");
}
}
}
main :: () {
check(20);
}warning[constant_condition]: this condition is always `false`
--> example.jai:5:12
|
5 | if count < 5 {
| ^^^^^^^^^
|
= help: the code it guards never runs: the values its operands can take here decide it; remove the test or fix the logic around it
= note: `constant_condition` is `warn` by default#import "Basic";
check :: (count: s64) {
if count > 10 {
if count < 50 {
print("between\n");
}
}
}
main :: () {
check(20);
}Reads the compiler's reachability facts (jaic::sema::reachability and jaic::ide::values, the code the editor fades): reports the condition behind a branch that never runs, such as if count < 5 inside if count > 10, or an else after a test that always holds.