Return statements in anonymous functions causing unreachable code warnings?

brlutzbrlutz 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

  • TobiaszTobiasz Posts: 16 ✭✭

    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

  • creigeldecreigelde 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.

  • TobiaszTobiasz Posts: 16 ✭✭
    edited April 29

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

Sign In or Register to comment.