Skip to content
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

Null coalescing assignment for nullable value type should set state of nullable type not underlying type #67468

Merged
merged 7 commits into from
Apr 17, 2023

Conversation

cston
Copy link
Member

@cston cston commented Mar 23, 2023

For a null coalescing assignment of a nullable value type, where the RHS is an instance of the underlying type, the nullable state of the LHS should be assigned a (non-null) nullable value type that wraps the state of the underlying value type from the RHS. Previously, the state of the LHS was set to the state from the RHS directly.

Fixes #67040

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 23, 2023
@cston cston changed the title Nullable state of null coalesing assignment should inherit from nullable type Null coalescing assignment for nullable value type should set state of nullable type not underlying type Mar 24, 2023
@cston cston marked this pull request as ready for review March 24, 2023 06:21
@cston cston requested a review from a team as a code owner March 24, 2023 06:21
@cston cston requested a review from a team April 4, 2023 15:54
Debug.Assert(actualType is { });
Debug.Assert(actualType.ContainsErrorType() ||
targetType.ContainsErrorType() ||
isOfTypeOrBaseOrInterface(actualType, targetType));
Copy link
Contributor

@RikkiGibson RikkiGibson Apr 7, 2023

Choose a reason for hiding this comment

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

Should we use some "classify conversion" API instead? e.g. if it's identity or implicit reference conversion, maybe that's good enough? #Resolved

@@ -5105,12 +5149,26 @@ private static BoundExpression SkipReferenceConversions(BoundExpression possibly
var leftState = this.State.Clone();
LearnFromNonNullTest(leftOperand, ref leftState);
LearnFromNullTest(leftOperand, ref this.State);

// If we are assigning the underlying value type to a nullable value type variable,
Copy link
Contributor

@RikkiGibson RikkiGibson Apr 7, 2023

Choose a reason for hiding this comment

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

I found this comment a little unclear. I think it should say that we do a special step to set the nullable variable's top level state within this block, then change the slot to later simulate an assignment from the RHS to the LHS's Value property, to update nullable states within the underlying value type. #Resolved

@cston cston merged commit e681754 into dotnet:main Apr 17, 2023
@cston cston deleted the 67040 branch April 17, 2023 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assert compiling dotnet/runtime in NullableWalker
3 participants