incomplete_enum_switch
Finds a switch on an enum that neither covers every member nor has a default case.
Category pedantic, allow by default.
Off by default; the example is shown with the rule enabled.
#import "Basic";
Shape :: enum {
CIRCLE;
SQUARE;
TRIANGLE;
}
sides :: (kind: Shape) -> int {
if kind == {
case .CIRCLE; return 0;
case .SQUARE; return 4;
}
return -1;
}
main :: () {
print("%\n", sides(.TRIANGLE));
}warning[incomplete_enum_switch]: this `switch` on `Shape` does not handle .TRIANGLE
--> example.jai:10:5
|
10 | if kind == {
| ^^^^^^^^^^^^
|
= help: handle them, or add `case;` for the rest, or write `#complete` so the compiler checks the list#import "Basic";
Shape :: enum {
CIRCLE;
SQUARE;
TRIANGLE;
}
sides :: (kind: Shape) -> int {
if kind == {
case .CIRCLE; return 0;
case .SQUARE; return 4;
case .TRIANGLE; return 3;
}
return -1;
}
main :: () {
print("%\n", sides(.TRIANGLE));
}Lists the members no case mentions. Mark the switch #complete so the compiler keeps the list current, or add case; to name the fallback.