Skip to content

Handle 'is' operators and patterns in definite assignment#52616

Merged
RikkiGibson merged 9 commits intodotnet:features/improved-definite-assignmentfrom
RikkiGibson:ida-is
Apr 20, 2021
Merged

Handle 'is' operators and patterns in definite assignment#52616
RikkiGibson merged 9 commits intodotnet:features/improved-definite-assignmentfrom
RikkiGibson:ida-is

Conversation

@RikkiGibson
Copy link
Member

@ghost ghost added the Area-Compilers label Apr 13, 2021
@RikkiGibson RikkiGibson marked this pull request as ready for review April 13, 2021 21:32
@RikkiGibson RikkiGibson requested a review from a team as a code owner April 13, 2021 21:32
@333fred
Copy link
Member

333fred commented Apr 16, 2021

Done review pass (commit 5). Didn't look through all the tests, just a few. #Closed


class C
{
int M0(object obj) => 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int [](start = 4, length = 3)

Consider a version where this returns int?.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And specifically include a case where you test against null.


In reply to: 615140930 [](ancestors = 615140930)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have expanded the test to cover these scenarios.

@333fred
Copy link
Member

333fred commented Apr 16, 2021

Done review pass (commit 7).

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 8)

@RikkiGibson
Copy link
Member Author

@jcouv Please take a look when you have the chance, need a second review.

case BoundDeclarationPattern:
return null;
default:
throw ExceptionUtilities.UnexpectedValue(pattern);
Copy link
Member

@jcouv jcouv Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should this be pattern.Kind? (same above) #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// 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)
Copy link
Member

@jcouv jcouv Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the local function probably needs a negation (either changing its name, or changing return values). #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Debug.Assert(negated == node.IsNegated);

if (VisitPossibleConditionalAccess(node.Expression, out var stateWhenNotNull))
{
Copy link
Member

@jcouv jcouv Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that we can assert that the state is not conditional. Consider adding assertion #Closed

Copy link
Member Author

@RikkiGibson RikkiGibson Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done #Closed

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with review pass (iteration 8). Only minor comment

@jcouv jcouv self-requested a review April 20, 2021 05:43
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with review pass (iteration 8). Only minor comment

@jcouv jcouv self-requested a review April 20, 2021 05:44
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with review pass (iteration 8). Only minor comment

@jcouv jcouv self-requested a review April 20, 2021 05:46
@jcouv
Copy link
Member

jcouv commented Apr 20, 2021

Something is messed up with GitHub. I left a comment (ie. didn't approve yet) and somehow the PR shows an approval...
I'll clear my review to avoid confusion.

image
image
#Resolved

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (iteration 9)

@jcouv jcouv self-assigned this Apr 20, 2021
@RikkiGibson RikkiGibson merged commit 667fb28 into dotnet:features/improved-definite-assignment Apr 20, 2021
@RikkiGibson RikkiGibson deleted the ida-is branch April 20, 2021 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants