Is this a bug in the compiler, or am I missing something?
public delegate bool Lambda<TState>([NotNullWhen(true)] out TState? state);
class Foo
{
void Bar()
{
var lambda = new Lambda<string>(
(out string? state) =>
{
state = default;
return false;
}
);
}
}
The compiler gives the following warning Foo.cs(14, 7): [CS8622] Nullability of reference types in type of parameter 'state' of 'lambda expression' doesn't match the target delegate 'Lambda<string>' (possibly because of nullability attributes).
But when I remove [NotNullWhen(true)]
warning disappears.
This behavior first appeared in .NET SDK 6.0.402
, there was no such warning in .NET SDK 6.0.101
.