absurd_comparison
Finds a comparison an unsigned value always passes or fails (u >= 0).
Category correctness, deny by default.
#import "Basic";
countdown :: (n: u32) {
i := n;
while i >= 0 {
print("%\n", i);
i -= 1;
}
}
main :: () {
countdown(3);
}error[absurd_comparison]: `i >= 0` is always `true`
--> example.jai:5:11
|
5 | while i >= 0 {
| ^^^^^^
|
help: `u32` is unsigned and holds nothing below 0; compare with a signed value, or drop the check
|
5 ~ while true {
|
= note: `absurd_comparison` is `deny` by default#import "Basic";
countdown :: (n: u32) {
i := n;
while i > 0 {
print("%\n", i);
i -= 1;
}
}
main :: () {
countdown(3);
}An unsigned value is never below zero, so counting down an unsigned i with while i >= 0 never stops.