Skip to content

Conversation

@DoctorKrolic
Copy link
Contributor

Redo of #74218
Related to #73894

@DoctorKrolic DoctorKrolic requested a review from a team as a code owner October 26, 2025 13:59
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Oct 26, 2025
if (leftOperand.HasAnyErrors || rightOperand.HasAnyErrors)
TypeSymbol leftType = leftOperand.Type;

var rightOperandTargetType = leftType switch
Copy link
Contributor

Choose a reason for hiding this comment

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

var rightOperandTargetType = leftType switch

We probably don't want to do this calculation for success scenarios.

var rightOperandTargetType = leftType switch
{
{ IsReferenceType: true } or { IsValueType: false, TypeKind: TypeKind.TypeParameter } => leftType,
{ IsValueType: true } when leftType.IsNullableType() => leftType.GetNullableUnderlyingType(),
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 27, 2025

Choose a reason for hiding this comment

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

leftType.GetNullableUnderlyingType()

Perhaps this would make sense when we are dealing with target-typed new, but I am not sure about other forms of the right operand.

else if (rightOperand.HasAnyErrors)
{
leftOperand = BindToTypeForErrorRecovery(leftOperand);
var conversion = GenerateConversionForAssignment(rightOperandTargetType, rightOperand, diagnostics, ConversionForAssignmentFlags.CompoundAssignment);
Copy link
Contributor

Choose a reason for hiding this comment

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

diagnostics

Let's suppress errors from this recovery.

else if (rightOperand.HasAnyErrors)
{
leftOperand = BindToTypeForErrorRecovery(leftOperand);
var conversion = GenerateConversionForAssignment(rightOperandTargetType, rightOperand, diagnostics, ConversionForAssignmentFlags.CompoundAssignment);
Copy link
Contributor

Choose a reason for hiding this comment

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

GenerateConversionForAssignment

Perhaps this would make sense when we are dealing with target-typed new, but I am not sure about other forms of the right operand.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1), nests were not looked at. It looks like the change affects scenarios that fall outside of the stated goal of this PR. I suggest making adjustments to affect only error scenarios with target typed new on the right.

else if (rightOperand.HasAnyErrors)
{
leftOperand = BindToTypeForErrorRecovery(leftOperand);
var conversion = GenerateConversionForAssignment(rightOperandTargetType, rightOperand, diagnostics, ConversionForAssignmentFlags.CompoundAssignment);
Copy link
Contributor

Choose a reason for hiding this comment

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

GenerateConversionForAssignment

We probably can pass the type to BindToTypeForErrorRecovery to get the same effect.

{
leftOperand = BindToTypeForErrorRecovery(leftOperand);
var conversion = GenerateConversionForAssignment(rightOperandTargetType, rightOperand, diagnostics, ConversionForAssignmentFlags.CompoundAssignment);
return new BoundNullCoalescingAssignmentOperator(node, leftOperand, conversion, rightOperandTargetType, hasErrors: true);
Copy link
Contributor

Choose a reason for hiding this comment

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

rightOperandTargetType

Why is this the right value to use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants