From 73b5ff584648396d6f3801c92079ebdb6dc350d2 Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Tue, 5 May 2026 09:47:55 +0200 Subject: [PATCH] C#: Adjust the extractor to correctly handle names for user defined increment and decrement operators. --- .../Semmle.Extraction.CSharp.Util/SymbolExtensions.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp.Util/SymbolExtensions.cs b/csharp/extractor/Semmle.Extraction.CSharp.Util/SymbolExtensions.cs index 92d7ecfad6b..50604e2404e 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.Util/SymbolExtensions.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.Util/SymbolExtensions.cs @@ -52,6 +52,13 @@ namespace Semmle.Extraction.CSharp.Util { "op_False", "false" } }); + /// + /// The operatorname for user-defined increment and decrement operators are "op_IncrementAssignment" and + /// "op_DecrementAssignment" respectively. + /// Thus we need to handle this explicitly to avoid postfixing them with an "=". + /// + private static bool isIncrementOrDecrement(string operatorName) => operatorName == "++" || operatorName == "--"; + /// /// Convert an operator method name in to a symbolic name. /// A return value indicates whether the conversion succeeded. @@ -72,7 +79,7 @@ namespace Semmle.Extraction.CSharp.Util if (match.Success && methodToOperator.TryGetValue($"op_{match.Groups[2]}", out var rawOperatorName)) { var prefix = match.Groups[1].Success ? "checked " : ""; - var postfix = match.Groups[3].Success ? "=" : ""; + var postfix = match.Groups[3].Success && !isIncrementOrDecrement(rawOperatorName) ? "=" : ""; operatorName = $"{prefix}{rawOperatorName}{postfix}"; return true; }