-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implicit field initialization in struct constructors #59788
Implicit field initialization in struct constructors #59788
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with review pass (iteration 32). Overall, looks very nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 33)
references: moduleReference, | ||
options: TestOptions.DebugDll.WithWarningLevel(5), | ||
parseOptions: TestOptions.Regular10, | ||
verify: Verification.Skipped); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while (true) | ||
{ | ||
var containingSlot = variableBySlot[fieldSlot].ContainingSlot; | ||
if (containingSlot == fieldSlot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.