No warning should be reported for the assignments:
#nullable enable
using System.Diagnostics.CodeAnalysis;
class Program
{
static void GetValue<T>([AllowNull]T x, [MaybeNull]out T y)
{
y = x; // warning CS8601: Possible null reference assignment
}
static bool TryGetValue<T>([AllowNull]T x, [MaybeNullWhen(false)]out T y)
{
y = x; // warning CS8601: Possible null reference assignment
return y != null;
}
}
For [MaybeNullWhen(...)], perhaps the compiler should allow assignment without warning to the variable regardless of the return value.
cc @stephentoub
No warning should be reported for the assignments:
For
[MaybeNullWhen(...)], perhaps the compiler should allow assignment without warning to the variable regardless of the return value.cc @stephentoub