-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Require definite assignment of all fields if struct includes any field initializers #57925
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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))) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It looks like this condition will be false for a synthesized parameter-less constructor of a class. Therefore, we are going to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks. I've updated the I'm open to suggestions on how to improve the readability of the enum ValueTypeConstructorKind
{
None,
Explicit,
ImplicitZeroInit,
ImplicitWithFieldInitializers,
} |
||
Analyze(compilation, method, block, diagnostics)) | ||
{ | ||
block = AppendImplicitReturn(block, method, originalBodyNested); | ||
|
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 find it a little brittle that we do this specifically for synthesized void methods. Basically, whenever a new synthesized void method is added to the compiler/language, we could forget to change this. Would it be possible to remove the condition, identify the problematic void methods that we don't want to analyze, and then introduce a new condition which excludes those methods more specifically? That way when a new kind of synthesized void method comes about it will just be analyzed by default and the author will have to make a special effort to opt out of it.
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'd like to keep this change simple if possible in case we want to port this change to other branches. I've logged #58012 to update the condition separately.