Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Return statements in anonymous functions causing unreachable code warnings?

brlutz
brlutz Posts: 1

I have some .NET C# code being analyzed with parasoft and it's flagging some fairly annoying warnings. The code has an anonymous function that contains a return statement that continues on to some other code, but I'm getting "unreachable code" error CS.PB.USC.UC-1.

Response _response = await this.WctCommunicationsService.SendAsync(
(Customer c) =>
{ return c.UpdateAsync(_request);},
nameof(UpdateCustomerRequest));

if(_response.Status == "Success") // parasoft-suppress CS.PB.USC.UC-1
{
DoSomethingElse();
}

return _whatever;

Has anyone else run into this? I feel like this is a valid use case and fully valid .NET 4.6.1 code. Suppressing is also messy because we don't allow comments on block elements due to our lint/stylecop rules, so we have to suppress parasoft and then suppress the linter at the same time.

Tagged:

Answers

  • Tobiasz
    Tobiasz Posts: 31 ✭✭

    Sorry for late response.

    Yes, it is a false positive and we already have an issue reported regarding this rule.

    To avoid adding a suppression in your code, you can add one using DTP suppressions:
    https://docs.parasoft.com/display/DOTTEST1033/Suppressing+Findings

  • creigelde
    creigelde Posts: 1

    It is a compile-time error if a statement cannot be executed because it is unreachable. This means that the control flow of your program can't get to that statement, but you assume that they would be. The compiler analyzes the flow, and reports these statements to you as error messages. It is a reliable indicators of logical error in your program.

  • Tobiasz
    Tobiasz Posts: 31 ✭✭
    edited April 2020

    @creigelde
    Sorry, but you are writing under dotTEST (the tool for .NET.) and your comment refers to Java.