C# 14: User increment/decrement support.#21827
Open
michaelnebel wants to merge 12 commits into
Open
Conversation
e93876d to
dab1525
Compare
Contributor
Author
|
DCA looks good
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds C# 14 support for user-defined instance increment/decrement operators (mutating this), updating both extraction and QL-side call/dispatch modeling so these operator calls are represented and dispatched correctly in the C# CodeQL libraries and tests.
Changes:
- Extend C# extractor operator-name handling to correctly render
op_*Assignment-style increment/decrement operators without appending=. - Add QL library support for modeling instance mutator operator calls and include them in dispatch logic alongside other instance-operator-style calls.
- Expand/adjust C# library tests (AST, operator call, and dataflow) to cover instance ++/-- (including
checkedforms) and extension-operator scenarios.
Show a summary per file
| File | Description |
|---|---|
| csharp/ql/test/library-tests/operators/PrintAst.expected | Updated AST expectation output to include new instance ++/-- operator declarations and call sites. |
| csharp/ql/test/library-tests/operators/Operators6.ql | New library-test query covering increment/decrement operator targets and calls. |
| csharp/ql/test/library-tests/operators/Operators6.expected | Expected results for the new operator-target/operator-call test. |
| csharp/ql/test/library-tests/operators/Operators5.expected | Updated expected locations due to added code shifting line numbers. |
| csharp/ql/test/library-tests/operators/Operators4.expected | Updated expected location due to added code shifting line numbers. |
| csharp/ql/test/library-tests/operators/Operators3.expected | Updated expected location due to added code shifting line numbers. |
| csharp/ql/test/library-tests/operators/operators.cs | Added a class with instance ++/-- operators and call sites (including checked block usage). |
| csharp/ql/test/library-tests/extension/PrintAst.expected | Updated AST expectations for extension operators, including ++/--. |
| csharp/ql/test/library-tests/extension/extensionTypes.expected | Updated expected locations due to added extension-operator content shifting line numbers. |
| csharp/ql/test/library-tests/extension/extensions.expected | Updated expected call/parameter/operator expectations to include ++/-- extension operators and new line numbers. |
| csharp/ql/test/library-tests/extension/extensions.cs | Added extension operator ++ and operator -- plus call sites to exercise extraction/dispatch. |
| csharp/ql/test/library-tests/dataflow/operators/operatorFlow.expected | Updated dataflow expectations to include flow through instance mutator operator ++. |
| csharp/ql/test/library-tests/dataflow/operators/Operator.cs | Added a new test class exercising mutation/dataflow through instance operator ++. |
| csharp/ql/lib/semmle/code/csharp/exprs/Call.qll | Introduced an InstanceMutatorOperatorCall concept for instance mutator operator invocations. |
| csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll | Updated dispatch modeling to treat instance operator calls (compound assignment + mutator) consistently. |
| csharp/ql/lib/semmle/code/csharp/Callable.qll | Updated unary-operator classification to allow parameterless non-static ++/-- operators. |
| csharp/ql/lib/change-notes/2026-05-12-user-increment-decrement.md | Added change note for the new C# 14 instance ++/-- operator support. |
| csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Invocation.cs | Updated invocation target-resolution to use context-aware GetTargetSymbol. |
| csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs | Refactored target-resolution to be context-driven and reused in call-type detection. |
| csharp/extractor/Semmle.Extraction.CSharp.Util/SymbolExtensions.cs | Adjusted operator-symbol rendering to avoid incorrectly producing ++=/--= for assignment-suffixed operator method names. |
Copilot's findings
- Files reviewed: 20/20 changed files
- Comments generated: 3
Comment on lines
+56
to
+58
| /// 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 "=". |
| /// "op_DecrementAssignment" respectively. | ||
| /// Thus we need to handle this explicitly to avoid postfixing them with an "=". | ||
| /// </summary> | ||
| private static bool isIncrementOrDecrement(string operatorName) => operatorName == "++" || operatorName == "--"; |
0fffdff to
4d850a2
Compare
… test expected output.
…ncrement and decrement operators.
…nstance increment and decrement operators.
4d850a2 to
fa2d633
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this PR we add support for user defined instance decrement/increment operators.
Example:
Similar to user defined compound assignment operators, the increment/decrement operators manipulates the instance they are applied to. This requires changes to the dispatch logic for such operator calls.