Skip to content

Commit baea40e

Browse files
authored
Implement CRef binding for compound assignment operators (#78111)
1 parent d3ff877 commit baea40e

File tree

5 files changed

+4053
-2598
lines changed

5 files changed

+4053
-2598
lines changed

src/Compilers/CSharp/Portable/Binder/Binder_Crefs.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,24 @@ private ImmutableArray<Symbol> BindOperatorMemberCref(OperatorMemberCrefSyntax s
225225
CrefParameterListSyntax? parameterListSyntax = syntax.Parameters;
226226
bool isChecked = syntax.CheckedKeyword.IsKind(SyntaxKind.CheckedKeyword);
227227

228-
// NOTE: Prefer binary to unary, unless there is exactly one parameter.
229-
// CONSIDER: we're following dev11 by never using a binary operator name if there's
230-
// exactly one parameter, but doing so would allow us to match single-parameter constructors.
231228
SyntaxKind operatorTokenKind = syntax.OperatorToken.Kind();
232-
string? memberName = parameterListSyntax != null && parameterListSyntax.Parameters.Count == 1
233-
? null
234-
: OperatorFacts.BinaryOperatorNameFromSyntaxKindIfAny(operatorTokenKind, isChecked);
229+
string? memberName;
235230

236-
memberName = memberName ?? OperatorFacts.UnaryOperatorNameFromSyntaxKindIfAny(operatorTokenKind, isChecked: isChecked);
231+
if (SyntaxFacts.IsOverloadableCompoundAssignmentOperator(operatorTokenKind))
232+
{
233+
memberName = OperatorFacts.CompoundAssignmentOperatorNameFromSyntaxKind(operatorTokenKind, isChecked);
234+
}
235+
else
236+
{
237+
// NOTE: Prefer binary to unary, unless there is exactly one parameter.
238+
// CONSIDER: we're following dev11 by never using a binary operator name if there's
239+
// exactly one parameter, but doing so would allow us to match single-parameter constructors.
240+
memberName = parameterListSyntax != null && parameterListSyntax.Parameters.Count == 1
241+
? null
242+
: OperatorFacts.BinaryOperatorNameFromSyntaxKindIfAny(operatorTokenKind, isChecked);
243+
244+
memberName = memberName ?? OperatorFacts.UnaryOperatorNameFromSyntaxKindIfAny(operatorTokenKind, isChecked: isChecked);
245+
}
237246

238247
if (memberName == null ||
239248
(isChecked && !syntax.OperatorToken.IsMissing && !SyntaxFacts.IsCheckedOperator(memberName))) // the operator cannot be checked

src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ private BoundExpression BindIncrementOperator(ExpressionSyntax node, ExpressionS
26492649
}
26502650
}
26512651

2652-
ArrayBuilder<MethodSymbol>? LookupUserDefinedInstanceOperators(TypeSymbol lookupInType, string? checkedName, string ordinaryName, int parameterCount, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
2652+
private ArrayBuilder<MethodSymbol>? LookupUserDefinedInstanceOperators(TypeSymbol lookupInType, string? checkedName, string ordinaryName, int parameterCount, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
26532653
{
26542654
Debug.Assert(parameterCount is 0 or 1);
26552655

0 commit comments

Comments
 (0)