|
|
|
|
|
by codebje
1544 days ago
|
|
Flow typing is purely a static analysis process. The representation of the type doesn't change, just the range of possible values in a scope constrained by some runtime condition. Some things that might have triggered warnings no longer need to, because if the runtime conditional evaluated to true there's no way the warning could take effect. Consider this little bit of C code: void foo(int x, unsigned y) {
if (x > y) {
printf("but it's bigger!?");
}
}
Due to the idiosyncrasies of C if you call foo(-1, 1) the test will promote x to an unsigned and the test will say x is bigger than y. There's a warning in most C compilers for it, because it's the sort of invisible bug that'll wreck your code.What's annoying, though, is if you do this: void foo(int x, unsigned y) {
if (x >= 0 && x > y) {
printf("but it's bigger!?");
}
}
And still get the warning. The compiler should be able to infer that the test x >= 0 means there's no fault path any more. Clang 13, at least, still warns.A C compiler using flow typing would not issue a warning for the second implementation of foo. Neither x nor y change representations. The execution path through your compiler for producing byte code doesn't change. A few of your tree structures might pick up an extra annotation for the provable facts the warning generator can use to improve its output, that's all. |
|