Parameterless struct constructors: Remaining work items#54811
Parameterless struct constructors: Remaining work items#54811jcouv merged 6 commits intodotnet:features/struct-ctorsfrom
Conversation
a3b4f10 to
5fc555d
Compare
| } | ||
| } | ||
|
|
||
| bool skipInitializer = false; |
| 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.
I think that's how we've indented such nested conditionals before.
There was a problem hiding this comment.
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 ? diagnostics : BindingDiagnosticBag.Discarded)); | ||
| } | ||
|
|
||
| internal static bool IsDefaultValueTypeConstructor(NamedTypeSymbol type, ConstructorInitializerSyntax initializerSyntax) |
| var comp = CreateCompilation(src); | ||
| comp.VerifyDiagnostics(); | ||
| CompileAndVerify(comp, expectedOutput: "(hello, hello, True, hello)"); | ||
| } |
There was a problem hiding this comment.
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.
Can we improve this error message? I don't understand what it's telling me. #WontFix
There was a problem hiding this comment.
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.
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.
333fred
left a comment
There was a problem hiding this comment.
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