Implicit field initialization in struct constructors#59788
Implicit field initialization in struct constructors#59788RikkiGibson merged 36 commits intodotnet:release/dev17.3from
Conversation
src/Compilers/CSharp/Test/Semantic/Semantics/StructConstructorTests.cs
Outdated
Show resolved
Hide resolved
| var builder = ArrayBuilder<BoundStatement>.GetInstance(implicitlyInitializedFields.Length + 1); | ||
| foreach (var field in implicitlyInitializedFields) | ||
| { | ||
| builder.Add(new BoundExpressionStatement( |
There was a problem hiding this comment.
Do we need a use site diagnostic here? see CodeGenTupleTests.CustomValueTuple_StructWithConstructor in this branch.
It might make more sense to give a "Missing compiler required member" on the tuple declaration which is missing the well-known fields.
There was a problem hiding this comment.
I'm leaning toward allowing the current behavior here. Declaring your own ValueTuple is a pretty rare thing to do and I wasn't able to find a decent way to introduce the use site diagnostics here without adding redundant use site diagnostics in other scenarios.
src/Compilers/CSharp/Portable/Errors/DiagnosticBagExtensions.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/StructConstructorTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/StructConstructorTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/StructConstructorTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/StructConstructorTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
Outdated
Show resolved
Hide resolved
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 32). Overall, looks very nice
| references: moduleReference, | ||
| options: TestOptions.DebugDll.WithWarningLevel(5), | ||
| parseOptions: TestOptions.Regular10, | ||
| verify: Verification.Skipped); |
There was a problem hiding this comment.
Consider modifying those tests to also verify execution (expectedOutput: should show reads of auto-defaulted values)
| { | ||
| var associatedSymbol = fieldSymbol.AssociatedSymbol; | ||
| var hasAssociatedProperty = associatedSymbol?.Kind == SymbolKind.Property; | ||
| var symbolName = associatedSymbol?.Kind == SymbolKind.Property ? associatedSymbol.Name : fieldSymbol.Name; |
| while (true) | ||
| { | ||
| var containingSlot = variableBySlot[fieldSlot].ContainingSlot; | ||
| if (containingSlot == fieldSlot) |
src/EditorFeatures/CSharpTest/ConvertTupleToStruct/ConvertTupleToStructTests.cs
Show resolved
Hide resolved
|
This is should be ready to go now @jaredpar. There are some test plan items that can be addressed in the coming weeks. |
…t-definite-assignment
Related to #60167
@cston @jcouv for review.
This design introduces a set of "disabled by default" diagnostics for definite assignment analysis of 'this' in struct constructors. Currently, in order to enable the diagnostics, the user would need to do something like the following:
I considered introducing some kind of shorthand which would allow specifying this whole set of diagnostics at once, but it feels like it might be worth waiting for user feedback before we add something like that.