import Toybox.Lang;
function foo(i as Number) as Number {
var t;
switch (i) {
case 1:
case 2:
return 0;
case 3:
t = 42;
break;
default:
t = 24;
break;
}
return t;
}
ERROR: <device>: bug.mc:16: Variable t may not have been initialized in all code paths.
I can fix it by putting another "return 0;" after "case 1:" - but I'm trying to save code size (and there's more code in the actual case statement I hit this problem with). Also, when doing this analysis, the compiler is clearly assuming that there's an implicit break before a case statement - which can't be good.