You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Debug.Assert(typeDecl.Kind()isSyntaxKind.RecordDeclaration or SyntaxKind.ClassDeclaration);
3584
+
Debug.Assert(typeDecl.Kind()isSyntaxKind.RecordDeclaration or SyntaxKind.ClassDeclaration or SyntaxKind.RecordStructDeclaration or SyntaxKind.StructDeclaration);
public void PrimaryCtorNullableFieldWarning(string typeKind)
22131
+
{
22132
+
var source = $$"""
22133
+
#nullable enable
22134
+
22135
+
public {{typeKind}} C()
22136
+
{
22137
+
public string Text { get; set; } // 1
22138
+
public C(bool ignored) : this() { }
22139
+
}
22140
+
22141
+
public {{typeKind}} C2
22142
+
{
22143
+
public string Text { get; set; }
22144
+
public C2() { } // 2
22145
+
}
22146
+
22147
+
public {{typeKind}} C3()
22148
+
{
22149
+
public string Text { get; set; } = "a";
22150
+
public C3(bool ignored) : this() { }
22151
+
}
22152
+
22153
+
public {{typeKind}} C4
22154
+
{
22155
+
public string Text { get; set; }
22156
+
public C4() { Text = "a"; }
22157
+
}
22158
+
""";
22159
+
22160
+
var comp = CreateCompilation(source);
22161
+
comp.VerifyEmitDiagnostics(
22162
+
// (5,19): warning CS8618: Non-nullable property 'Text' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
// (12,12): warning CS8618: Non-nullable property 'Text' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public void RecordPrimaryCtorNullableFieldWarning(string typeKind)
22176
+
{
22177
+
var source = $$"""
22178
+
#nullable enable
22179
+
22180
+
public record {{typeKind}} C()
22181
+
{
22182
+
public string Text { get; set; } // 1
22183
+
public C(bool ignored) : this() { }
22184
+
}
22185
+
22186
+
public record {{typeKind}} C2
22187
+
{
22188
+
public string Text { get; set; }
22189
+
public C2() { } // 2
22190
+
}
22191
+
22192
+
public record {{typeKind}} C3()
22193
+
{
22194
+
public string Text { get; set; } = "a";
22195
+
public C3(bool ignored) : this() { }
22196
+
}
22197
+
22198
+
public record {{typeKind}} C4
22199
+
{
22200
+
public string Text { get; set; }
22201
+
public C4() { Text = "a"; }
22202
+
}
22203
+
""";
22204
+
22205
+
var comp = CreateCompilation(source);
22206
+
comp.VerifyEmitDiagnostics(
22207
+
// (5,19): warning CS8618: Non-nullable property 'Text' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
// (12,12): warning CS8618: Non-nullable property 'Text' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
0 commit comments