Skip to content

Fix regression with var pattern nullability#53691

Merged
jcouv merged 4 commits intodotnet:mainfrom
jcouv:var-nullability
May 28, 2021
Merged

Fix regression with var pattern nullability#53691
jcouv merged 4 commits intodotnet:mainfrom
jcouv:var-nullability

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented May 26, 2021

There was a regression in LearnFromDecisionDag in 16.10 for top-level var patterns in #51001

Also fix #52925 (type of var should have an annotation) and #46236 (GetDeclaredSymbol on such var declarations)
Note that any change to the inferred type of var is breaking in ref var scenario. We've hit this in bootstrap build and I've added a test to illustrate.

@jcouv jcouv added this to the 17.0 milestone May 26, 2021
@jcouv jcouv self-assigned this May 26, 2021
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 The issue was that makeDagTempSlot above was recording the type of the var pattern local into State, based on correct state (from expressionType), but we'd drop that by using initialState which captured a prior state.

@jcouv jcouv force-pushed the var-nullability branch from 22096bc to 12c2f04 Compare May 26, 2021 06:58
@jcouv jcouv force-pushed the var-nullability branch from 8341dcc to 1ef2e51 Compare May 26, 2021 19:29
@jcouv jcouv marked this pull request as ready for review May 27, 2021 17:50
@jcouv jcouv requested a review from a team as a code owner May 27, 2021 17:50
@jcouv
Copy link
Member Author

jcouv commented May 27, 2021

@RikkiGibson @cston @dotnet/roslyn-compiler for review. Thanks

@jcouv
Copy link
Member Author

jcouv commented May 27, 2021

I'll take a look to see if this also fixed #46236 (Thanks Chuck)

@RikkiGibson RikkiGibson self-assigned this May 27, 2021
ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported();
ReturnFound:
ref var value = ref entry._value;
ref TValue value = ref entry._value;
Copy link
Member

Choose a reason for hiding this comment

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

It wasn't clear to me why this needed to change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't bootstrap without this change

{
var type = TypeWithAnnotations.Create(Type, NullableAnnotation.NotAnnotated);
return State == NullableFlowState.MaybeDefault ? type.SetIsAnnotated(compilation) : type;
return (State == NullableFlowState.MaybeDefault || asAnnotatedType) ? type.SetIsAnnotated(compilation) : type;
Copy link
Member

Choose a reason for hiding this comment

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

Was this all that was needed to fix the 'foreach' scenario?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the for loop starts with a local declaration. That's handled by VisitLocalDeclaration, which correctly calls ToAnnotatedTypeWithAnnotations when the local has an inferred type, but when we get to ToTypeWithAnnotations the annotation would get dropped.

@jcouv jcouv enabled auto-merge (squash) May 28, 2021 05:36
@jcouv jcouv merged commit 3fa5dff into dotnet:main May 28, 2021
@ghost ghost modified the milestones: 17.0, Next May 28, 2021
@jcouv jcouv deleted the var-nullability branch May 28, 2021 19:06
jcouv added a commit to jcouv/roslyn that referenced this pull request Jun 1, 2021
@RikkiGibson RikkiGibson removed this from the Next milestone Jun 29, 2021
@RikkiGibson RikkiGibson added this to the 17.0.P2 milestone Jun 29, 2021
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.

var nullability analysis regression

3 participants