Why in code like below is the .NET compiler not able to establish that all code paths do return a value?
bool Test(bool param) {
bool test = true;
if
Let's backward analyze the code:
Problem: Code doesn't return any value.
Question: Where in code a value is returned?
Answer: Just at the last line.
Conclusion: So that line of code (last line) should always return a value.
Question: Does last line always return a value?
Answer: No, it only returns value if test is false while it has been set to true at the first line.
Conclusion: As compiler says, this function never returns a value while it is supposed to return bool.