The method return analysis does not analyze the if condition to make sure that it is always true or false, because, as a rule, this will not be a compile-time constant (otherwise you will not write if in the first place). He simply sees that there exists an if that may or may not be accepted, and if it was not accepted, the method does not return a value, hence an error.
The dead code analysis is performed in a separate passage to the method return analysis, which does a more in-depth analysis that looks at the internal branching conditions.
My completely ignorant assumption is that this behavior is an artifact of how the compiler was designed; method return analysis is an important part of compilation so that you can get a valid program at the end, and this has become one of the main functions implemented in the first place. Parsing dead code is “nice to have,” and so it was implemented later using more sophisticated algorithms (since the bits of the main compiler were completed at this point)
thecoop
source share