Skip to content
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

Merged
merged 6 commits into from
Jul 22, 2021

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Jul 14, 2021

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

@jcouv jcouv force-pushed the parameterless-ctors branch from a3b4f10 to 5fc555d Compare July 14, 2021 15:53
@jcouv jcouv marked this pull request as ready for review July 14, 2021 17:53
@jcouv jcouv requested a review from a team as a code owner July 14, 2021 17:53
}
}

bool skipInitializer = false;
Copy link
Member

@cston cston Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false

Consider inlining the if condition. #Closed

constructor.Initializer == null ? null : bodyBinder.BindConstructorInitializer(constructor.Initializer, diagnostics),
skipInitializer ? new BoundNoOpStatement(constructor, NoOpStatementFlavor.Default)
: initializer == null ? null
: bodyBinder.BindConstructorInitializer(initializer, diagnostics),
Copy link
Member

@cston cston Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:

Should this be indented further, since it's associated with the nested conditional expression? #Resolved

Copy link
Member Author

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.

Copy link
Member

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)
Copy link
Member

@cston cston Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsDefaultValueTypeConstructor

Consider moving back to MemberSymbolExtensions, perhaps as an extension method on NamedTypeSymbol type, since this is not related to the Binder. #Closed

var comp = CreateCompilation(src);
comp.VerifyDiagnostics();
CompileAndVerify(comp, expectedOutput: "(hello, hello, True, hello)");
}
Copy link
Member

@cston cston Jul 19, 2021

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

@jcouv
Copy link
Member Author

jcouv commented Jul 20, 2021

@333fred @dotnet/roslyn-compiler for second review. Thanks

@jcouv jcouv requested a review from cston July 20, 2021 16:37
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),
Copy link
Member

@333fred 333fred Jul 20, 2021

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@333fred 333fred left a 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.

@jcouv jcouv merged commit 9057dcf into dotnet:features/struct-ctors Jul 22, 2021
@jcouv jcouv deleted the parameterless-ctors branch July 22, 2021 00:53
333fred added a commit to 333fred/roslyn that referenced this pull request Jul 23, 2021
* 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
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants