I mistakenly wrote this code with error
fn point(letter: u8) u32 {
switch(letter) {
'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T' => 1,
'D', 'G' => 2,
'B', 'C', 'M', 'P' => 3,
'F', 'H', 'V', 'W', 'Y' => 4,
'K' => 5,
'J', 'X' => 8,
'Q', 'Z' => 10,
else => unreachable
}
}
The mistake was I did not have a return statement. But the compilation error I got was
scrabble_score.zig:11:4: error: value with comptime-only type 'comptime_int' depends on runtime control flow
scrabble_score.zig:11:11: note: runtime control flow here
My question is what does this error message mean? and how could I have understood it to be able to easily tell what the issue is because I ended up founding my error by staring long at the code, because the compile error message was not helpful…
The fixed code with the return statement.
fn point(letter: u8) u32 {
return switch(letter) {
'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T' => 1,
'D', 'G' => 2,
'B', 'C', 'M', 'P' => 3,
'F', 'H', 'V', 'W', 'Y' => 4,
'K' => 5,
'J', 'X' => 8,
'Q', 'Z' => 10,
else => unreachable
};
}