Possible bug (?): message 'left operand is never null'

Take this code:

public void Test(Type t)
{
   string name = t.FullName ?? "unnamed";
}


The text "unnamed" is grayed out and the tooltip "'??' left operand is never null" is shown.
But according to the MSDN documentation, "FullName" can be null.

4 comments
Comment actions Permalink
I can't comment on your reported issue - but I did search the net and oddly found this:http://dotnetinside.com/en/framework/JetBrains/JetBrains.ReSharper.Daemon.CSharp/NullCoalescingConditionIsAlwaysNotNullWarning I've never heard of "dotnetinside" and had no idea people were publishing reversed engineered intellectual property - what's all this about?Hugh.PS: I cant get many of the tools here to work like making text bold, insering URL links, making text different colors etc - I'm acessing the forum through IE 10.Also it seems to be removing spaces are thus removing paragraph spacing so it looks like Ive posted one long line of text.
0
Comment actions Permalink

Which documentation did you look at? The MSDN documentation clearly states:

The fully qualified name of the Type, including the namespace of the Type but not the assembly; or null if the current instance represents a generic type parameter, an array type, pointer type, or byref type based on a type parameter, or a generic type that is not a generic type definition but contains unresolved type parameters.
0
Comment actions Permalink
Yes, that it is the documentation I am referring to.Therefore, ReSharper's warning message seems to be wrong to me, because FullName is allowed to be null.
0
Comment actions Permalink
No static analysis can tell if that property of that parameter can ever be null or not-null; neither the C# compiler nor the ReSharper tool can reliably deduce this.Its a public method and so nothing can be known about the possible callers of the method and so there is no enough information for this error to be reliably reported - in my view it is not only a bug it's a fundamnetal error in the analyzer.A reference type can always conceivably be null unless we prove that at that point it can't be null - for example if there was an assignmnet from a non-null value immediately before the "if" but there is no such thing in that fragment.I've seen several very odd messages reported by ReSharper and I cannot trust what it says I'm afraid.Hugh
0

Please sign in to leave a comment.