SonarCloud reports incorrect "unreachable code" error on C#

In this SonarCloud run on my open source github project, I received a bug report saying “unreachable code”. What’s odd is that I have a unit test that asserts that this code path is indeed reachable.

The code in question looks like this:

New code
            // At least one prefix matched, but the keys weren't valid
            if (prefixMatches == 1)
            {
                return new ApiKeyResult() { Message = lastAlgorithmFailedMessage };
            }
            if (prefixMatches == 0)
Change this condition so that it does not always evaluate to 'True'. Some code paths are unreachable.
            {
                return new ApiKeyResult() { Message = "Key prefix does not match any supported key algorithms." };
            }
            return 
new ApiKeyResult() { Message = "Invalid API key hash." };

It’s possible for my code to generate zero, one, or many matches, and I want it to return different error messages in each case. I have unit tests for each scenario and they all pass. Any idea why SonarCloud thinks this code is unreachable?

I think this link will work to see the issue, since this is an open source library and SonarCloud should be visible for it: SonarCloud

Hi,

By the time I tried the link, nothing showed up. Is this still available to you? Could you share a screenshot?

 
Thx,
Ann