Skip to content

Commit

Permalink
Require definite assignment of all fields if struct includes any fiel…
Browse files Browse the repository at this point in the history
…d initializers
  • Loading branch information
cston committed Nov 22, 2021
1 parent 5b20a71 commit 2b4b523
Show file tree
Hide file tree
Showing 4 changed files with 532 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static BoundBlock Rewrite(
if (method.ReturnsVoid || method.IsIterator || method.IsAsyncEffectivelyReturningTask(compilation))
{
// we don't analyze synthesized void methods.
if ((method.IsImplicitlyDeclared && !method.IsScriptInitializer) ||
if ((method.IsImplicitlyDeclared && !method.IsScriptInitializer && (!method.IsParameterlessConstructor() || method.IsDefaultValueTypeConstructor(requireZeroInit: true))) ||
Analyze(compilation, method, block, diagnostics))
{
block = AppendImplicitReturn(block, method, originalBodyNested);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4932,19 +4932,19 @@ public void Struct_ImplementSynthesizedConstructor()
struct S
{
int a = 1;
int b;
int b = 2;
}
";
var source1 =
@"
struct S
{
int a = 1;
int b;
int b = 2;
public S()
{
b = 2;
b = 3;
}
}
";
Expand Down
Loading

0 comments on commit 2b4b523

Please sign in to comment.