-
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
Add parsing for the with-expression form #42304
Conversation
@@ -9091,6 +9093,10 @@ private ExpressionSyntax ParseExpressionContinued(ExpressionSyntax leftOperand, | |||
{ | |||
opKind = SyntaxKind.SwitchExpression; | |||
} | |||
else if (tk == SyntaxKind.WithKeyword && this.PeekToken(1).Kind == SyntaxKind.OpenBraceToken) |
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 you even need the open brace? it couldn't be legal otherwise, right? so maybe just try to parse here and say that the {
is missing.
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.
Maybe? I don't know. I can't think of how it would be ambiguous, but maybe I'm just not thinking of something :)
3f97fca
to
d18582b
Compare
<Kind Name="OpenBraceToken"/> | ||
</Field> | ||
<!-- PROTOTYPE: This is the same syntax as for an anonymous object creation, but do we want to share the nodes? --> | ||
<Field Name="Initializers" Type="SeparatedSyntaxList<AnonymousObjectMemberDeclaratorSyntax>" AllowTrailingSeparator="true" /> |
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.
Have you considered nested withers? Something like:
record with { Owner = { Name = "name" } }
->
record.With(owner: record.Owner.With(name: "name"))
Also, it seems like collections could use some help, we already have this pattern:
node with { ArgList = { Args = { 1 } } }
->
node.With(argList: node.ArgList.With(args: node.ArgList.Args.Add(1))
though with that syntax it's not clear if we want Add
or a complete replacement.
edit: in fact, if we wanted a replacement, we could say { Args = new .. }
that's exactly how collection initializers work today.
So I think it would be actually more similar to object/collection initializers, at least syntactically.
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.
Nested withers is a neat idea, but out of scope for this PR, I think. We would have to discuss it and approve it in the design meeting.
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.
Filed dotnet/csharplang#3262
@@ -23,219 +23,6 @@ protected override SyntaxTree ParseTree(string text, CSharpParseOptions options) | |||
return SyntaxFactory.ParseSyntaxTree(text, options ?? TestOptions.Regular); | |||
} | |||
|
|||
[Fact] | |||
public void RecordParsing01() |
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.
RecordParsing01 [](start = 20, length = 15)
Why delete these tests? #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.
Woops, did not mean to, just meant to consolidate into a single file. Re-added. #Resolved
Finished review (Iteration 1) #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.
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 4)
Relates to #40726 (test plan for records)