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.
| } | ||
|
|
||
| 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.
Lots of failing tests for this completion provider.
{ $$ } always see a list pattern clause.
|
|
||
| // 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.
Just one, failing in the previous test runs.
For cases with no failing test I added a comment to cover later.
jcouv
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
Added a few tests. Let me know if you have any specific scenario that is not covered.
There was a problem hiding this comment.
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)
|
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 |
jcouv
left a comment
There was a problem hiding this comment.
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 1or 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