From d9ef9f82e16d3d2cfb2c3c1fdacbb82cfbdc95a8 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Thu, 5 Mar 2026 14:41:38 +0100 Subject: [PATCH] C#: Make Assignment extend BinaryOperation. --- csharp/ql/lib/semmle/code/csharp/exprs/Assignment.qll | 6 +++++- csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll | 3 ++- csharp/ql/test/library-tests/linq/Linq2.ql | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/csharp/ql/lib/semmle/code/csharp/exprs/Assignment.qll b/csharp/ql/lib/semmle/code/csharp/exprs/Assignment.qll index a5576f023d7..9fa2a93724d 100644 --- a/csharp/ql/lib/semmle/code/csharp/exprs/Assignment.qll +++ b/csharp/ql/lib/semmle/code/csharp/exprs/Assignment.qll @@ -11,7 +11,7 @@ import Expr * (`LocalVariableDeclAndInitExpr`), a simple assignment (`AssignExpr`), or * an assignment operation (`AssignOperation`). */ -class Assignment extends Operation, @assign_expr { +class Assignment extends BinaryOperation, @assign_expr { Assignment() { this instanceof LocalVariableDeclExpr implies @@ -20,6 +20,10 @@ class Assignment extends Operation, @assign_expr { expr_parent(_, 0, this) } + override Expr getLeftOperand() { result = this.getChild(1) } + + override Expr getRightOperand() { result = this.getChild(0) } + /** Gets the left operand of this assignment. */ Expr getLValue() { result = this.getChild(1) } diff --git a/csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll b/csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll index ada01065258..1294cdb7c02 100644 --- a/csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll +++ b/csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll @@ -233,7 +233,8 @@ class UnaryOperation extends Operation, @un_op { * A binary operation. Either a binary arithmetic operation * (`BinaryArithmeticOperation`), a binary bitwise operation * (`BinaryBitwiseOperation`), a comparison operation (`ComparisonOperation`), - * or a binary logical operation (`BinaryLogicalOperation`). + * a binary logical operation (`BinaryLogicalOperation`), or an + * assignment (`Assignment`). */ class BinaryOperation extends Operation, @bin_op { /** Gets the left operand of this binary operation. */ diff --git a/csharp/ql/test/library-tests/linq/Linq2.ql b/csharp/ql/test/library-tests/linq/Linq2.ql index b3909f88b70..5f1fc3de85b 100644 --- a/csharp/ql/test/library-tests/linq/Linq2.ql +++ b/csharp/ql/test/library-tests/linq/Linq2.ql @@ -5,4 +5,5 @@ import csharp from BinaryOperation e +where not e instanceof Assignment select e, e.getAnOperand()