Skip to content

Commit 06e61e6

Browse files
committed
C#: Adjust the extractor to correctly handle names for user defined increment and decrement operators.
1 parent ed5722f commit 06e61e6

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

csharp/extractor/Semmle.Extraction.CSharp.Util/SymbolExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public static string GetName(this ISymbol symbol, bool useMetadataName = false)
5252
{ "op_False", "false" }
5353
});
5454

55+
/// <summary>
56+
/// The operatorname for user-defined increment and decrement operators are "op_IncrementAssignment" and
57+
/// "op_DecrementAssignment" respectively.
58+
/// Thus we need to handle this explicitly to avoid postfixing them with an "=".
59+
/// </summary>
60+
private static bool isIncrementOrDecrement(string operatorName) => operatorName == "++" || operatorName == "--";
61+
5562
/// <summary>
5663
/// Convert an operator method name in to a symbolic name.
5764
/// A return value indicates whether the conversion succeeded.
@@ -72,7 +79,7 @@ public static bool TryGetOperatorSymbol(this ISymbol symbol, out string operator
7279
if (match.Success && methodToOperator.TryGetValue($"op_{match.Groups[2]}", out var rawOperatorName))
7380
{
7481
var prefix = match.Groups[1].Success ? "checked " : "";
75-
var postfix = match.Groups[3].Success ? "=" : "";
82+
var postfix = match.Groups[3].Success && !isIncrementOrDecrement(rawOperatorName) ? "=" : "";
7683
operatorName = $"{prefix}{rawOperatorName}{postfix}";
7784
return true;
7885
}

0 commit comments

Comments
 (0)