ReSharper 2016.1 Nullability and unreachable code analysis seems to have issues.

Answered


When a method's return value has an unspecified nullability, it seems to treat it as always null.

Here's a simple console application to repro [Visual Studio 2015; no ReSharper Extensions].

using System;
 
namespace ConsoleApplication2
{
    static class Program
    {
        static void Main()
        {
            var foo = MakeAString();
            Console.WriteLine(foo?.Length);
            Console.WriteLine(foo.Length);
        }
 
        private static string MakeAString()
        {
            return new string(new[] { 'f''o''o' });
        }
    }
}

 

5 comments
Comment actions Permalink

Seems the same problem:

 

var vm = DataContext as MyViewModel;
if (null == vm) // shown as "always true"
return;

// here "unreachable code" begin
0
Comment actions Permalink

I got the same issues. Here two good examples of the strange behavior:

 

1. In this example I'm debugging into the code from which R# says it cannot happen.

2. Perhaps the same cause but here it says I can get a NullRefException while casting my object to a custom enum. Also the code after that line would be unreachable... And getting back to line 421, this warning says that my object will always be null.

Any feedback would be appreciated.

0
Comment actions Permalink

I have used installation from Issue RSRP-458210 and it helps.

1
Comment actions Permalink

Thanks @Yevhen, that helped! I installed the fixed version and my issues were gone. :-)

0

Please sign in to leave a comment.