This is a language design issue:
What do you think, inaccessible code (in programming languages in general) should raise a warning (ie, “report problem and compilation anyway”) or an error (“refuse compilation”)?
Personally, I strongly feel that this should be a mistake: if a programmer writes a piece of code, he should always be with the intention of actually running it in some kind of script. But the C # compiler, for example, disagrees with this and simply reports a warning.
Note. I understand that finding good dead code is a very difficult problem, but this is not the focus of this issue.
Here are some sample code snippets where some statements are clearly unattainable:
return; foo();
-
throw new Exception(); foo();
-
if (...) { return; } else { throw new Exception(); } foo();
compiler-construction language-agnostic language-design
Martijn Feb 17 2018-10-17T00 : 00Z
source share