-
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
List pattern syntax #51299
List pattern syntax #51299
Conversation
This comment has been minimized.
This comment has been minimized.
I couldn't find the csharplang spec/proposal. Was it uploaded? #Closed |
Not yet. The proposal is updated at dotnet/csharplang#3245 #Closed |
This comment has been minimized.
This comment has been minimized.
@@ -124,7 +124,7 @@ private static SyntaxToken TryGetOpenBraceOrCommaInPropertyPatternClause(SyntaxT | |||
return default; | |||
} | |||
|
|||
return token.Parent.IsKind(SyntaxKind.PropertyPatternClause) ? token : default; | |||
return token.Parent.IsKind(SyntaxKind.PropertyPatternClause, SyntaxKind.ListPatternClause) ? token : default; |
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.
Is there a test for this change?
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.
Lots of failing tests for this completion provider.
{ $$ }
always see a list pattern clause.
@@ -219,7 +220,7 @@ private void AddBlockIndentationOperation(List<IndentBlockOperation> list, Synta | |||
} | |||
|
|||
// for lambda, set alignment around braces so that users can put brace wherever they want | |||
if (node.IsLambdaBodyBlock() || node.IsAnonymousMethodBlock() || node.IsKind(SyntaxKind.PropertyPatternClause) || node.IsKind(SyntaxKind.SwitchExpression)) | |||
if (node.IsLambdaBodyBlock() || node.IsAnonymousMethodBlock() || node.IsKind(SyntaxKind.PropertyPatternClause, SyntaxKind.ListPatternClause) || node.IsKind(SyntaxKind.SwitchExpression)) |
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 we have a corresponding test?
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.
Just one, failing in the previous test runs.
For cases with no failing test I added a comment to cover later.
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.
Compiler changes LGTM Thanks (iteration 23)
The correctness leg reports a diagnostic that probably needs to be suppressed: |
07f1138
to
2a8e5b3
Compare
@333fred @dotnet/roslyn-compiler for a second review. Thanks |
<Field Name="DotDotToken" Type="SyntaxToken"> | ||
<Kind Name="DotDotToken"/> | ||
</Field> | ||
<Field Name="Pattern" Type="PatternSyntax" Optional="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.
Is there an example for what this field is being used for? The proposal implied that nothing can be listed after the .. in the list or that there was still an open question there.
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.
The proposal implied that nothing can be listed after the .. in the list
That's true only for enumerable and multi-dimensional arrays.
For compatible types this optionally matches the returned slice. See https://github.com/dotnet/csharplang/blob/main/proposals/list-patterns.md#lowering-on-countableindexeablesliceable-type
src/Compilers/CSharp/Test/Syntax/Parsing/PatternParsingTests_ListPatterns.cs
Show resolved
Hide resolved
} | ||
|
||
[Fact] | ||
public void SlicePattern_10() |
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.
It would be good to have variations on these slice tests that have the ..
after the other pattern component. Also, some pattern combinations with positional and length patterns would be good.
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.
Added a few tests. Let me know if you have any specific scenario that is not covered.
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'd expect to see some of the previous variations you had here. For example, c is { {}.. }
from SlicePattern_05
. I'd go through your existing tests and add flipped versions of these.
In reply to: 608770979 [](ancestors = 608770979)
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.
Done.
Done review pass (commit 24). Code looks good, but I'd like a few more tests before signing off. #Closed |
Done review pass (commit 25) |
…t-patterns-syntax # Conflicts: # src/Compilers/CSharp/Portable/CSharpResources.resx # src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf # src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
@333fred Please take another look |
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 28). @jcouv, do you want to take another look?
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.
Still LGTM Thanks (iteration 28)
Merged/squashed. Thanks! |
FYI, this is pending a few open questions especially around binding which I'm going to do next. |
@jcouv That's not all. Look for "open question" in the document. A few of those are critical to move forward with the first iteration of list patterns. |
@alrz Collected the open issues from the list-pattern spec:
Tagging @dotnet/roslyn-compiler as FYI |
@jcouv Ok, that is not very distant from my draft except for "explicit range indexer support" that needs to be added. I will tidy it up and finish the array match lowering for review. Would you prefer a single PR or should I divide it up?
That's only a question on the lowering strategy. Given array.GetLength(0) == 1 && array.GetLength(1) == 1 && array[0, 0] is 1
array.GetLength(0) == 1 && array.GetLength(1) == 1 &&
array.GetLowerBound(0) is var b0 && array.GetLowerBound(1) is var b1 &&
array[b0 + 0, b1 + 0] is 1 or something else? I think the latter is actually the correct one, but needed a confirmation. EDIT: I will do md arrays separately, I think that makes it a lot more manageable. |
A few questions on md arrays in addition to the lowering issue above:
|
Spec: https://github.com/dotnet/csharplang/blob/main/proposals/list-patterns.md
Test plan: #51289