-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Open
Copy link
Description
Follow up to #75554
[Fact]
public void NullableAnalysis_02()
{
// The expected warning is missing here.
// Problem: the conditional receiver and its field are getting their own slots.
// But, when the assignment '.F = null' is processed, we do look up the slot for 'c' thru 'NullableWalker._lastConditionalAccessSlot'.
// Thus the state for 'c.F' gets updated to maybe-null, but the state for '<placeholder>.F' remains not-null.
// When we get a slot for RHS of next 'c?.F' expression, we get the slot for '<placeholder>.F', and see the .F as having not-null state.
// We may want to solve this by ensuring we don't create a slot for the placeholder, and that getting a slot for the placeholder always gives the slot for the original receiver instead.
var source = """
#nullable enable
class C
{
string? F;
static void M1()
{
var c = new C { F = "a" };
c.F.ToString();
c?.F = null;
c?.F.ToString(); // 1
}
}
""";
var comp = CreateCompilation(source);
comp.VerifyEmitDiagnostics();
}