-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Refactor binary operator binding in preparation for future work. #78832
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
Conversation
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.
@@ -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)) |
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.
return createBadCompoundAssignmentOperator(node, kind, left, right, resultKind, originalUserDefinedOperators, diagnostics); | ||
} | ||
|
||
if (best.Signature.Method is { } bestMethod) |
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.
@@ -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)) |
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.
@@ -865,6 +957,12 @@ private bool BindSimpleBinaryOperatorParts(BinaryExpressionSyntax node, BindingD | |||
{ | |||
var signature = best.Signature; | |||
|
|||
if (signature.Method is { } bestMethod) |
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.
var best = this.BinaryOperatorOverloadResolution(kind, isChecked: CheckOverflowAtRuntime, left, right, allowExtensions: true, node, diagnostics, out lookupResult, out originalUserDefinedOperators); | ||
BinaryOperatorAnalysisResult best; | ||
|
||
if (!IsTypelessExpressionAllowedInBinaryOperator(kind, left, right)) |
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.
@@ -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) |
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.
return possiblyBest; | ||
|
||
BinaryOperatorAnalysisResult nonExtensionOverloadResolution( |
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.
return possiblyBest; | ||
} | ||
|
||
static BinaryOperatorAnalysisResult analyzeOverloadResolutionResult(BinaryOperatorOverloadResolutionResult result, out LookupResultKind resultKind, out ImmutableArray<MethodSymbol> originalUserDefinedOperators) |
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.
@jcouv, @dotnet/roslyn-compiler Please review. |
@jcouv, @dotnet/roslyn-compiler Please review. |
bool checkOverflowAtRuntime, | ||
BoundExpression left, | ||
BoundExpression right, | ||
ref AnalyzedArguments? analyzedArguments, |
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.
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
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.
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.
@jcouv, @dotnet/roslyn-compiler For the second review. |
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.
LGTM Thanks (iteration 2)
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
anddefault
operands.