-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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-patterns: add a few tests and add HasValidate flag #57914
Conversation
|
||
if (hasValidate) | ||
{ | ||
WriteLine("private partial void Validate();"); |
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.
💡 Would be nice to add something like [Conditional("DEBUG")] partial void Validate();
for all nodes
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 agree, it feels like the design of partial methods is such that we shouldn't need to introduce new flags to BoundNodes.xml or branches in this logic. Just unconditionally emit the declaration part and the call, then trust the compiler to eliminate the methods and calls to methods that lack implementations.
That said, it's fine with me if the desire is to use a flag in the xml to reduce clutter in the PR.
@@ -238,7 +238,6 @@ private BoundExpression BindSwitchExpression(SwitchExpressionSyntax node, Bindin | |||
pattern = BindPattern(node.Pattern, sliceType, GetValEscape(sliceType, inputValEscape), permitDesignations, hasErrors, diagnostics); | |||
} | |||
|
|||
Debug.Assert(GetIndexerOrImplicitIndexerSymbol(indexerAccess) is var _); |
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.
@@ -317,7 +316,6 @@ private BoundExpression BindSwitchExpression(SwitchExpressionSyntax node, Bindin | |||
inputValEscape, permitDesignations, typeSyntax: null, diagnostics, ref hasErrors, | |||
out Symbol? variableSymbol, out BoundExpression? variableAccess); | |||
|
|||
Debug.Assert(GetIndexerOrImplicitIndexerSymbol(indexerAccess) is var _); |
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.
@@ -108,6 +108,10 @@ public override bool IsEquivalentTo(BoundDagEvaluation obj) | |||
return base.IsEquivalentTo(obj) && | |||
this.Index == ((BoundDagIndexerEvaluation)obj).Index; | |||
} | |||
private partial void Validate() |
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.
|
||
private partial void Validate() | ||
{ | ||
Debug.Assert(LengthOrCountAccess is BoundPropertyAccess or BoundLocal); |
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.
private partial void Validate() | ||
{ | ||
Debug.Assert(LengthOrCountAccess is BoundPropertyAccess or BoundLocal); | ||
Debug.Assert(IndexerOrSliceAccess is BoundIndexerAccess or BoundCall); |
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.
This is going to "conflict" with the array PR (#57918). Consider adding BoundArrayAccess into the list. #Closed
I think this line should move to Validate. In reply to: 977085556 In reply to: 977085556 Refers to: src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs:226 in 3ed14b9. [](commit_id = 3ed14b9, deletion_comment = False) |
I think this line should move to Validate. In reply to: 977090678 Refers to: src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs:372 in 3ed14b9. [](commit_id = 3ed14b9, deletion_comment = False) |
var csCompilation = CreateCompilation(csSource, parseOptions: TestOptions.RegularWithListPatterns, references: new[] { vbCompilation.EmitToImageReference() }); | ||
// PROTOTYPE(list-patterns) Unsupported because the lookup fails not that the indexer is static | ||
var csCompilation = CreateCompilation(csSource, references: new[] { vbCompilation.EmitToImageReference() }); | ||
// Note: the VB indexer's name is "Item" but C# looks for "this[]", but we can't put Default on Shared indexer declaration |
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.
We have a test with a static indexer from IL, see SlicePattern_LengthAndIndexAndSliceAreStatic
Are we testing scenarios with an instance property like that (expected name but not Default member)? In reply to: 977102228 #Closed Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs:1396 in 3ed14b9. [](commit_id = 3ed14b9, deletion_comment = False) |
I don't know how to do the first suggestion (C# looks for In reply to: 977102228 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs:1396 in 3ed14b9. [](commit_id = 3ed14b9, deletion_comment = False) |
private partial void Validate() | ||
{ | ||
Debug.Assert(LengthOrCountAccess is BoundPropertyAccess or BoundLocal or BoundBadExpression); | ||
Debug.Assert(IndexerOrSliceAccess is BoundIndexerAccess or BoundCall or BoundArrayAccess or BoundBadExpression); |
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.
private partial void Validate() | ||
{ | ||
Debug.Assert(LengthAccess is null or BoundPropertyAccess or BoundBadExpression); | ||
Debug.Assert(IndexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess or BoundBadExpression or BoundDynamicIndexerAccess); |
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.
{ | ||
private partial void Validate() | ||
{ | ||
Debug.Assert(IndexerAccess is BoundIndexerAccess or BoundImplicitIndexerAccess or BoundArrayAccess or BoundBadExpression or BoundDynamicIndexerAccess); |
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.
Can it be null? #Closed
switch (a) | ||
{ | ||
case [..[1],2,3]: | ||
case [1,2,3]: // no error |
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.
Because we inject a null test for reference types (int[]
vs. Span<int>
) that we get back from the slice operation. We're having an email thread with LDM on this.
Done with review pass (commit 9) |
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 10)
@@ -53,6 +53,14 @@ try { | |||
} | |||
} | |||
|
|||
# Verify no TODO2 marker left |
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.
@jcouv is this something we expect to be useful on an ongoing basis? should we do something like flip the existing TODO comments over to TODO2 and change this to prevent introduction of new TODO comments to main?
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 don't think we can do much about existing TODO comments. I've been using TODO2 comments to track things within a PR and having this helps me ensure I don't let any into the main branch or feature branches.
Additional validation:
Test plan: #51289