-
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
Parameterless struct constructors: Remaining work items #54811
Parameterless struct constructors: Remaining work items #54811
Conversation
a3b4f10
to
5fc555d
Compare
} | ||
} | ||
|
||
bool skipInitializer = false; |
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.
constructor.Initializer == null ? null : bodyBinder.BindConstructorInitializer(constructor.Initializer, diagnostics), | ||
skipInitializer ? new BoundNoOpStatement(constructor, NoOpStatementFlavor.Default) | ||
: initializer == null ? null | ||
: bodyBinder.BindConstructorInitializer(initializer, diagnostics), |
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.
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 think that's how we've indented such nested conditionals before.
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.
If it is, then when I next stumble onto those cases I'll reformat for readability. The way this is formatted is very confusing.
constructor.Body == null ? null : (BoundBlock)bodyBinder.BindStatement(constructor.Body, diagnostics), | ||
constructor.ExpressionBody == null ? | ||
null : | ||
bodyBinder.BindExpressionBodyAsBlock(constructor.ExpressionBody, | ||
constructor.Body == null ? diagnostics : BindingDiagnosticBag.Discarded)); | ||
} | ||
|
||
internal static bool IsDefaultValueTypeConstructor(NamedTypeSymbol type, ConstructorInitializerSyntax initializerSyntax) |
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.
var comp = CreateCompilation(src); | ||
comp.VerifyDiagnostics(); | ||
CompileAndVerify(comp, expectedOutput: "(hello, hello, True, hello)"); | ||
} |
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.
Are we testing calls to the following constructors?
record struct S4
{
public string field = "hello";
public S4(object o) : this() { }
}
record struct S5()
{
public string field = "hello";
public S5(object o) : this() { }
}
record struct S6(string other)
{
public string field = "hello";
public S6() : this(null) { }
}
``` #Closed
@333fred @dotnet/roslyn-compiler for second review. Thanks |
comp.VerifyDiagnostics( | ||
// (13,5): error CS8862: A constructor declared in a record with parameter list must have 'this' constructor initializer. | ||
// S3(object o) { } // 1 | ||
Diagnostic(ErrorCode.ERR_UnexpectedOrMissingConstructorInitializerInRecord, "S3").WithLocation(13, 5), |
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.
Can we improve this error message? I don't understand what it's telling me. #WontFix
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 suppose this is probably out of scope for this PR, but I really do find this confusing.
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.
As I mentioned offline, this error message correctly describes the problem. But we can certainly improve the wording separately from the parameterless struct ctor feature work if you have a suggestion.
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 (commit 5) with ternary formatting fix.
* upstream/main: (249 commits) Switch back queue name to default (dotnet#55064) Fix 'code model' with file scoped namespaces Map documents to be reanalyzed back from compile-time to design-time documents (dotnet#55054) Update MSBuild Workspace test projects target framework Enable CA1069 for ErrorCode and MessageID (dotnet#54695) Dev16->17 updates Update global.json Record completion of "parameterless struct constructor" feature (dotnet#55049) Generalize rude edit messages to be applicable to both Hot Reload and EnC (dotnet#55012) Update azure-pipelines-official.yml Update azure-pipelines-integration.yml Merge pull request dotnet#54992 from jaredpar/so-big Parameterless struct constructors: Remaining work items (dotnet#54811) Update docs/wiki/Diagnosing-Project-System-Build-Errors.md update queue name Dev16->17 changes Fix test Fix 'move type' with file scoped namespaces Fix 'match folder and namespace' with file scoped namespaces Log NFW ...
This is addressing remaining work items in test plan: #51698
See spec for expected execution of field initializers and
: this()
representing a default value type constructor:https://github.com/dotnet/csharplang/blob/main/proposals/parameterless-struct-constructors.md#executing-field-initializers