[Epic] Specify nullable reference types in C# 8
#700 is a draft which will be useful, but we're going to try to do this in multiple small PRs.
The current planned task list is:
- [x] #1088
- [x] #1089
- [x] #1090
- [ ] #1091
- [ ] #1092
- [ ] #1093
- [ ] #1094
Are MaybeNullWhenAttribute and others going to be standardised?
Does any of those issues cover how variance of generic parameters should affect warnings about identity conversions:
using System;
public class C {
// f1 is a delegate that takes string? and returns string.
public void M(Func<string?, string> f1) {
// Nullability of type arguments does not match,
// but there is no warning, because of variance.
Func<string, string?> f2 = f1;
// Convert back to the original type.
// This causes a warning.
Func<string?, string> f3 = f2;
}
}
https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/nullable-reference-types-specification.md doesn't seem to mention this.
I'm not sure whether this behaviour is C# 8 or 9, but I guess 8.
Terminology question: Do we want to use "nullable context" or "null analysis context"? Alternative is "set the flags in the nullable context".
See https://github.com/dotnet/csharpstandard/pull/1123/files#r1672741166
However, note that the null state analysis is always being done. The comment states that the context may impact that.