Handle 'is' operators and patterns in definite assignment#52616
Handle 'is' operators and patterns in definite assignment#52616RikkiGibson merged 9 commits intodotnet:features/improved-definite-assignmentfrom
Conversation
|
Done review pass (commit 5). Didn't look through all the tests, just a few. #Closed |
|
|
||
| class C | ||
| { | ||
| int M0(object obj) => 1; |
There was a problem hiding this comment.
int [](start = 4, length = 3)
Consider a version where this returns int?.
There was a problem hiding this comment.
And specifically include a case where you test against null.
In reply to: 615140930 [](ancestors = 615140930)
There was a problem hiding this comment.
Have expanded the test to cover these scenarios.
|
Done review pass (commit 7). |
|
@jcouv Please take a look when you have the chance, need a second review. |
| case BoundDeclarationPattern: | ||
| return null; | ||
| default: | ||
| throw ExceptionUtilities.UnexpectedValue(pattern); |
There was a problem hiding this comment.
nit: should this be pattern.Kind? (same above) #Closed
| // Returns `true` if the pattern only matches if the top-level input is not null. | ||
| // Returns `false` if the pattern only matches if the top-level input is null. | ||
| // Otherwise, returns `null`. | ||
| static bool? isTopLevelNullTest(BoundPattern pattern) |
There was a problem hiding this comment.
the local function probably needs a negation (either changing its name, or changing return values). #Closed
| Debug.Assert(negated == node.IsNegated); | ||
|
|
||
| if (VisitPossibleConditionalAccess(node.Expression, out var stateWhenNotNull)) | ||
| { |
There was a problem hiding this comment.
I assume that we can assert that the state is not conditional. Consider adding assertion #Closed
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 8). Only minor comment
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 8). Only minor comment
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 8). Only minor comment


Related to #51463
Implements the following section of the spec: https://github.com/dotnet/csharplang/blob/main/proposals/improved-definite-assignment.md#is-operator-and-is-pattern-expressions