Add support for with(...) element parsing. #80545
Add support for with(...) element parsing. #80545CyrusNajmabadi merged 66 commits intodotnet:features/collection-expression-argumentsfrom
with(...) element parsing. #80545Conversation
| ? _syntaxFactory.SpreadElement(this.EatDotDotToken(), this.ParseExpressionCore()) | ||
| : _syntaxFactory.ExpressionElement(this.ParseExpressionCore()); | ||
| if (this.CurrentToken.ContextualKind == SyntaxKind.WithKeyword && | ||
| this.PeekToken(1).Kind == SyntaxKind.OpenParenToken && |
There was a problem hiding this comment.
Who are we helping with this open-paren check? I'd suggest doing away with it I guess it's fine to be more specific (only break the minimum we need) #Closed
There was a problem hiding this comment.
i'm follow the grammar here. There's nothing wrong with having with on its own here. :)
There was a problem hiding this comment.
I don't like this, but, I think it's consistent to have a with lacking parens here, being treated as a normal identifier.
Just waiting for Jared to write the blog post about the meaning of [with(with), with].
I compared with an attribute [assembly] lacking :, as the closest analogy that entered my head, which is allowed. .NET Lab.
There was a problem hiding this comment.
Sorry. I misread. I thought you were asking me to change this. .
| missingSyntaxKinds.Add(SyntaxKind.CollectionExpression); | ||
| missingSyntaxKinds.Add(SyntaxKind.ExpressionElement); | ||
| missingSyntaxKinds.Add(SyntaxKind.SpreadElement); | ||
| missingSyntaxKinds.Add(SyntaxKind.WithElement); |
There was a problem hiding this comment.
We'll want to all-in-one syntax resource. We can either:
- add it now
- mark as PROTOTYPE to add it before merging to
main - leave with follow-up link
There are two problems with option 3:
- the linked issue was specific to one kind of syntax. I've updated its title now, since it looks like it tracks more syntax kinds
- I'd prefer we avoid digging the hole deeper, as that means it's less and less likely that we fix it and essentially we give up on all-in-one in practice
There was a problem hiding this comment.
Have done this in #80555. Whichever goes in first, i will fix the other.
...torFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs
Show resolved
Hide resolved
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (commit 60)
…i/roslyn into withElementSyntax2
|
@333fred ptal. |
|
or @RikkiGibson since you're also looking at Collection Expressions :) |
| : _syntaxFactory.ExpressionElement(this.ParseExpressionCore()); | ||
| if (this.CurrentToken.ContextualKind == SyntaxKind.WithKeyword && | ||
| this.PeekToken(1).Kind == SyntaxKind.OpenParenToken && | ||
| IsFeatureEnabled(MessageID.IDS_FeatureCollectionExpressionArguments)) |
There was a problem hiding this comment.
It would be good if we can make a LangVersion error work in binding, if we can't bind with in [with()], to hint that maybe you meant to update your language version instead. There may be a similar error for record Rec() { ... } in language versions where record is treated as a method return type, or some similar case like that.
There was a problem hiding this comment.
Sure. we can add that to the upcoming semantic work :)
| [Fact] | ||
| public void TestSyntaxFacts() | ||
| { | ||
| Assert.Equal(SyntaxKind.WithKeyword, SyntaxFacts.GetContextualKeywordKind("with")); |
There was a problem hiding this comment.
... only now realizing why with was already a contextual keyword.
| [Theory, MemberData(nameof(CollectionArgumentsLanguageVersions))] | ||
| public void NotWithElement12(LanguageVersion languageVersion) | ||
| { | ||
| UsingExpression("[with..with()]", |
| Diagnostic(ErrorCode.ERR_CloseParenExpected, "]").WithLocation(1, 7), | ||
| // (1,8): error CS1003: Syntax error, ']' expected | ||
| // [with(] | ||
| Diagnostic(ErrorCode.ERR_SyntaxError, "").WithArguments("]").WithLocation(1, 8)); |
There was a problem hiding this comment.
Ah, the diagnostics are the same with both parses. Neat
| // [a:b, with()] | ||
| Diagnostic(ErrorCode.ERR_SyntaxError, "b").WithArguments(",").WithLocation(1, 4)); | ||
|
|
||
| if (languageVersion == LanguageVersion.CSharp14) |
There was a problem hiding this comment.
nit: it looks like this test could be condensed to use 'CollectionARgumentsOrInvocation' helper. Possibly i am missing something?
| [Theory, MemberData(nameof(CollectionArgumentsLanguageVersions))] | ||
| public void WithElement36(LanguageVersion languageVersion) | ||
| { | ||
| UsingExpression("[..with()]", |
There was a problem hiding this comment.
I'm inclined to think of the leading with as like the leading .. for spread elements, which leads me to wonder if we have a parsing test for something like [.. ..x].
This is not an actionable comment for this PR, just a thought that crossed my mind.
There was a problem hiding this comment.
yes we do. TestSpreadOfRange1 and TestSpreadOfRange2
| } | ||
| } | ||
| M(SyntaxKind.CommaToken); | ||
| CollectionArgumentsOrInvocation(languageVersion); |
There was a problem hiding this comment.
Is this expected? I thought that with a prefix await, that this would parse as an invocation always.
There was a problem hiding this comment.
in this case, because we're not in an async block, the await is itself an expression (not the start of an async-expression). so this is parsed as [await , with()] (just with a missing comma). See the next test for an async context.
| N(SyntaxKind.IdentifierToken, "await"); | ||
| } | ||
| } | ||
| M(SyntaxKind.CommaToken); |
e219fbf
into
dotnet:features/collection-expression-arguments
Spec: https://github.com/dotnet/csharplang/blob/main/proposals/collection-expression-arguments.md
Relates to test plan #80613