Skip to content

Conversation

AlekseyTs
Copy link
Contributor

In the process a small bug was fixed. Binding of instance compound assignment operators was made consistent with binding against static binary operators with respect to implicit object creation and default operands.

In the process a small bug was fixed. Binding of instance compound assignment operators was made consistent with binding against static binary operators with respect to `implicit object creation` and `default` operands.
@AlekseyTs AlekseyTs requested review from jjonescz and jcouv June 5, 2025 16:31
@AlekseyTs AlekseyTs requested a review from a team as a code owner June 5, 2025 16:31
@AlekseyTs AlekseyTs added Area-Compilers Feature - Extension Everything The extension everything feature labels Jun 5, 2025
@@ -114,11 +114,26 @@ private BoundExpression BindCompoundAssignment(AssignmentExpressionSyntax node,
leftPlaceholder: null, leftConversion: null, finalPlaceholder: null, finalConversion: null, LookupResultKind.NotAVariable, CreateErrorType(), hasErrors: true);
}

if (!IsTypelessExpressionAllowedInBinaryOperator(kind, left, right))
Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 5, 2025

Choose a reason for hiding this comment

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

IsTypelessExpressionAllowedInBinaryOperator

This check used to be in BinaryOperatorOverloadResolution #Resolved

return createBadCompoundAssignmentOperator(node, kind, left, right, resultKind, originalUserDefinedOperators, diagnostics);
}

if (best.Signature.Method is { } bestMethod)
Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 5, 2025

Choose a reason for hiding this comment

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

if (best.Signature.Method is { } bestMethod)

Logic in this if used to be in BinaryOperatorOverloadResolution #Resolved

@@ -847,7 +929,17 @@ private bool BindSimpleBinaryOperatorParts(BinaryExpressionSyntax node, BindingD
out BinaryOperatorSignature resultSignature, out BinaryOperatorAnalysisResult best)
{
bool foundOperator;
best = this.BinaryOperatorOverloadResolution(kind, isChecked: CheckOverflowAtRuntime, left, right, allowExtensions: true, node, diagnostics, out resultKind, out originalUserDefinedOperators);

if (!IsTypelessExpressionAllowedInBinaryOperator(kind, left, right))
Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 5, 2025

Choose a reason for hiding this comment

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

IsTypelessExpressionAllowedInBinaryOperator

This check used to be in BinaryOperatorOverloadResolution #Resolved

@@ -865,6 +957,12 @@ private bool BindSimpleBinaryOperatorParts(BinaryExpressionSyntax node, BindingD
{
var signature = best.Signature;

if (signature.Method is { } bestMethod)
Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 5, 2025

Choose a reason for hiding this comment

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

if (signature.Method is { } bestMethod)

Logic in this if used to be in BinaryOperatorOverloadResolution #Resolved

var best = this.BinaryOperatorOverloadResolution(kind, isChecked: CheckOverflowAtRuntime, left, right, allowExtensions: true, node, diagnostics, out lookupResult, out originalUserDefinedOperators);
BinaryOperatorAnalysisResult best;

if (!IsTypelessExpressionAllowedInBinaryOperator(kind, left, right))
Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 5, 2025

Choose a reason for hiding this comment

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

IsTypelessExpressionAllowedInBinaryOperator

This check used to be in BinaryOperatorOverloadResolution #Resolved

@@ -1134,6 +1243,12 @@ private BoundExpression BindConditionalLogicalOperator(BinaryExpressionSyntax no
// bool, or we've got a valid user-defined operator.
BinaryOperatorSignature signature = best.Signature;

if (signature.Method is { } bestMethod)
Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 5, 2025

Choose a reason for hiding this comment

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

if (signature.Method is { } bestMethod)

Logic in this if used to be in BinaryOperatorOverloadResolution #Resolved

return possiblyBest;

BinaryOperatorAnalysisResult nonExtensionOverloadResolution(
Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 5, 2025

Choose a reason for hiding this comment

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

nonExtensionOverloadResolution

This local function got extracted as BinaryOperatorNonExtensionOverloadResolution method. #Resolved

return possiblyBest;
}

static BinaryOperatorAnalysisResult analyzeOverloadResolutionResult(BinaryOperatorOverloadResolutionResult result, out LookupResultKind resultKind, out ImmutableArray<MethodSymbol> originalUserDefinedOperators)
Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 5, 2025

Choose a reason for hiding this comment

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

analyzeOverloadResolutionResult

This local function got extracted as BinaryOperatorAnalyzeOverloadResolutionResult method #Resolved

@AlekseyTs
Copy link
Contributor Author

@jcouv, @dotnet/roslyn-compiler Please review.

@jcouv jcouv self-assigned this Jun 5, 2025
@RikkiGibson RikkiGibson self-assigned this Jun 5, 2025
@AlekseyTs
Copy link
Contributor Author

@jcouv, @dotnet/roslyn-compiler Please review.

bool checkOverflowAtRuntime,
BoundExpression left,
BoundExpression right,
ref AnalyzedArguments? analyzedArguments,
Copy link
Member

@RikkiGibson RikkiGibson Jun 6, 2025

Choose a reason for hiding this comment

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

It might be reasonable to make this an out AnalyzedArguments analyzedArguments, since it doesn't look like the value coming in is used, and then the assertion at the call site could be removed. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be reasonable to make this an out AnalyzedArguments analyzedArguments, since it doesn't look like the value coming in is used, and then the assertion at the call site could be removed.

In the next PR it will be used as a "true" ref parameter.

@AlekseyTs
Copy link
Contributor Author

@jcouv, @dotnet/roslyn-compiler For the second review.

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 2)

@AlekseyTs AlekseyTs merged commit 1af8578 into dotnet:features/extensions Jun 9, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Extension Everything The extension everything feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants