A couple of minor suggestions

I don't frequent the forums much (hardly at all) so you'll have to forgive me if this is the wrong place for this.

I guess this first one is also a question..

private void SomeMethod
{
     if (foo())
     {
          if (bar())
          {
               return;
          }
          return;
     }
     return; // <-- this line is marked as redundant as it lies before the end of the method, are not the above two redundant as well?
}

second one is this

if (someEnumerable.Aggregate(false, (a, b) => b.foo())) //<-- imo this should be marked as "Expression is always false."
{
     do stuff...
}

3 comments
Comment actions Permalink

For the first item, the other two "return" statements are only redundant if there's no code following them. If you remove the last "return" statement, you should see the previous one flagged as redundant.

For the second, why should it always be "false"? The result of the expression will be whatever the "foo" method returns for the last item in the "someEnumerable" sequence.

Your code is equivalent to:

bool result = false;
foreach (var b in someEnumerable)
{
   result = b.foo();
}

if (result)
{
   do stuff...
}


Unless the sequence is empty, the initial value you specificy has no effect.

0
Comment actions Permalink

I know I'm late to the party...  

For the first item, the other two "return" statements are only redundant if there's no code following them. If you remove the last "return" statement, you should see the previous one flagged as redundant.
Obviously, that's why I said as much, there is no code (that is not redundant) following them so they are redundant.  Resharper is smart enough to know for the last, it should be analyze whatever is preceding redundant code in the same way it analyzes that redundant code to know whether or not the preceding is also redundant.

For the second, that was a misunderstanding on my part of how LINQ's aggregate worked.  I thought it stored the result internally to compare to the following values (now knowing how it works that's obviously ridiculous but too late now).

0
Comment actions Permalink

claudekennilol wrote:

Obviously, that's why I said as much, there is no code (that is not redundant) following them so they are redundant.


There's a significant difference between "there's no code following this statement" and "all the code following this statement is redundant". I would imagine that adding a recursive check for the latter case could cause serious performance problems.

0

Please sign in to leave a comment.