-
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
Null coalescing assignment for nullable value type should set state of nullable type not underlying type #67468
Conversation
…f nullable type not underlying type
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Jones <[email protected]>
Debug.Assert(actualType is { }); | ||
Debug.Assert(actualType.ContainsErrorType() || | ||
targetType.ContainsErrorType() || | ||
isOfTypeOrBaseOrInterface(actualType, targetType)); |
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.
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, |
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 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
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