uninit_read
Finds a variable declared = --- read before anything is written to it.
Category correctness, deny by default.
#import "Basic";
sum :: (xs: [] int) -> int {
total: int = ---;
for xs total += it;
return total;
}
main :: () {
print("%\n", sum(int.[1, 2, 3]));
}error[uninit_read]: `total` is read here before anything is written to it
--> example.jai:5:12
|
5 | for xs total += it;
| ^^^^^
|
help: `= ---` leaves `total` holding whatever was in memory: give it a value first, or drop the `= ---`
|
4 ~ total: int;
|
= note: `uninit_read` is `deny` by default#import "Basic";
sum :: (xs: [] int) -> int {
total := 0;
for xs total += it;
return total;
}
main :: () {
print("%\n", sum(int.[1, 2, 3]));
}The first mention after the declaration, in the same block, decides; a write anywhere (even inside an if) ends the check, so only straight-line reads are reported.