We found the following bug in our code as a result of a git merge.
public static void error(ref string test)
{
var diff = 123 - new Random().Next();
if (diff == 0)
test = $"diff == 0";
{
return;
}
//This will never execute
test = $"diff != 0";
}
As you can see the missing braces has caused a block statement with a return in it. Code analysis reports the code as unreachable which would alert most people. A unit test would also pick this up. However the issue is a block statement is rarely ever the programmers intention and during the git merge this error is not immediately obvious (due to no code analysis running in most merge windows).
Is there anyway to make this (the block statement, not the unreachable code) a compile error/warning via custom analysis rules in C# via Jetbrains Rider or Visual Studio?