未验证 提交 f83c5f76 编写于 作者: A Andy Gocke 提交者: GitHub

Don't track uninitialized non-null struct fields (#34292)

It' s already an error to fail to initialize a field of a struct, so
this warning is just a duplication of a more serious error condition

Fixes #30022
上级 440f83b8
......@@ -33,7 +33,7 @@ internal static void Analyze(CSharpCompilation compilation, MethodSymbol method,
return;
}
if (HasThisConstructorInitializer(method))
if (HasThisConstructorInitializer(method) || method.ContainingType.IsValueType)
{
return;
}
......
......@@ -691,13 +691,7 @@ internal S(string s)
Diagnostic(ErrorCode.ERR_UnassignedThisAutoProperty, "S").WithArguments("S.P").WithLocation(6, 14),
// (6,14): error CS0171: Field 'S.F' must be fully assigned before control is returned to the caller
// internal S(string s)
Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("S.F").WithLocation(6, 14),
// (6,14): warning CS8618: Non-nullable property 'P' is uninitialized.
// internal S(string s)
Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S").WithArguments("property", "P").WithLocation(6, 14),
// (6,14): warning CS8618: Non-nullable field 'F' is uninitialized.
// internal S(string s)
Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "S").WithArguments("field", "F").WithLocation(6, 14));
Diagnostic(ErrorCode.ERR_UnassignedThis, "S").WithArguments("S.F").WithLocation(6, 14));
}
[Fact]
......@@ -714,8 +708,7 @@ public void EmptyStruct()
comp.VerifyDiagnostics();
}
// https://github.com/dotnet/roslyn/issues/30022: Struct assign `this`.
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/30022")]
[Fact]
[WorkItem(30022, "https://github.com/dotnet/roslyn/issues/30022")]
public void StructAssignThis()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册