-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Extensions: Confirm whether we should track nullable state for extension properties #81913
Copy link
Copy link
Open
Description
We're waiting for additional customer feedback on this, so please do thumbs-up this issue and comment with some motivating usage scenarios.
The current design is that we don't track state for extension properties. Will double check.
[Fact]
public void Nullability_Setter_09()
{
// property's state
var src = """
#nullable enable
object o = new object();
o.P = null;
o.P.ToString(); // 1
o.P.ToString(); // 2
o.P = new object();
o.P.ToString(); // 3
o.P.ToString(); // 4
static class E
{
extension(object o)
{
public object? P { get => throw null!; set => throw null!; }
}
}
""";
CreateCompilation(src).VerifyEmitDiagnostics(
// (5,1): warning CS8602: Dereference of a possibly null reference.
// o.P.ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "o.P").WithLocation(5, 1),
// (6,1): warning CS8602: Dereference of a possibly null reference.
// o.P.ToString(); // 2
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "o.P").WithLocation(6, 1),
// (9,1): warning CS8602: Dereference of a possibly null reference.
// o.P.ToString(); // 3
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "o.P").WithLocation(9, 1),
// (10,1): warning CS8602: Dereference of a possibly null reference.
// o.P.ToString(); // 4
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "o.P").WithLocation(10, 1));
src = """
#nullable enable
C o = new C();
o.P = null;
o.P.ToString(); // 1
o.P.ToString();
o.P = new object();
o.P.ToString();
class C
{
public object? P { get => throw null!; set => throw null!; }
}
""";
CreateCompilation(src).VerifyEmitDiagnostics(
// (5,1): warning CS8602: Dereference of a possibly null reference.
// o.P.ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "o.P").WithLocation(5, 1));
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Type
Fields
Give feedbackNo fields configured for issues without a type.