JetBrains/ExternalAnnotations

Nullability of `System.Object.ToString` differs from the NRT annotation in System.Private.Corelib

akarpov89 opened this issue · 1 comments

The System.Object.ToString method is annotated with NotNull attribute while nullability annotation given to return type of this method in System.Private.Corelib is string? (https://source.dot.net/#System.Private.CoreLib/shared/System/Object.cs,39).

This difference causes ReSharper to issue warnings where compiler doesn't complain. For instance,

void Foo(object arg)
{
  var x = arg.ToString() ?? string.Empty;
                          //^^^^^^^^^^^^ left operand is never null
}

I'm not sure if we need to update our annotation for Object.ToString to CanBeNull because it will cause lots of false positives. Maybe just remove NotNull and leave it "oblivious".

/cc @sirduke

removed NotNull for "ToString" in .netcore and .netstandard