Decorated the out parameter of ResourceIdentifier.TryParse() with MaybeNullWhen#39332
Decorated the out parameter of ResourceIdentifier.TryParse() with MaybeNullWhen#39332abatishchev wants to merge 1 commit intoAzure:mainfrom
Conversation
|
Thank you for your contribution @abatishchev! We will review the pull request and get back to you soon. |
| /// </param> | ||
| /// <returns> True if the parse operation was successful; otherwise, false. </returns> | ||
| public static bool TryParse(string input, out ResourceIdentifier? result) | ||
| public static bool TryParse(string input, [MaybeNullWhen(false)] out ResourceIdentifier? result) |
There was a problem hiding this comment.
Tested this to validate and apparently the warning always exists if the out var is nullable so the attribute seems to make no difference.
If we change to
public static bool TryParse(string input, [MaybeNullWhen(false)] out ResourceIdentifier result)Then it seems to work as expected. I don't now the backwards compatibility rules on nullable annotation changes. @KrzysztofCwalina is there another link I should be using besides https://learn.microsoft.com/en-us/dotnet/core/compatibility/library-change-rules to check?
My guess is going from ResourceIdentifier to ResourceIdentifier? is fine but going from ResourceIdentifier? to ResourceIdentifier is not?
namespace nullable
{
internal class Program
{
static void Main(string[] args)
{
if (Foo.TryParse("x", out var y))
Console.WriteLine(y.Length); //does not give warning
Foo.TryParse("x", out var y2);
Console.WriteLine(y2.Length); //gives warning cs8602
}
}
internal class Foo
{
public static bool TryParse(string x, [MaybeNullWhen(false)] out string y)
{
y = null;
return false;
}
}
}|
API change check API changes are not detected in this pull request. |
Split from #39060.
Updated:
with: