Skip to content

Commit d9ef9f8

Browse files
committed
C#: Make Assignment extend BinaryOperation.
1 parent ffa5110 commit d9ef9f8

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

csharp/ql/lib/semmle/code/csharp/exprs/Assignment.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Expr
1111
* (`LocalVariableDeclAndInitExpr`), a simple assignment (`AssignExpr`), or
1212
* an assignment operation (`AssignOperation`).
1313
*/
14-
class Assignment extends Operation, @assign_expr {
14+
class Assignment extends BinaryOperation, @assign_expr {
1515
Assignment() {
1616
this instanceof LocalVariableDeclExpr
1717
implies
@@ -20,6 +20,10 @@ class Assignment extends Operation, @assign_expr {
2020
expr_parent(_, 0, this)
2121
}
2222

23+
override Expr getLeftOperand() { result = this.getChild(1) }
24+
25+
override Expr getRightOperand() { result = this.getChild(0) }
26+
2327
/** Gets the left operand of this assignment. */
2428
Expr getLValue() { result = this.getChild(1) }
2529

csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ class UnaryOperation extends Operation, @un_op {
233233
* A binary operation. Either a binary arithmetic operation
234234
* (`BinaryArithmeticOperation`), a binary bitwise operation
235235
* (`BinaryBitwiseOperation`), a comparison operation (`ComparisonOperation`),
236-
* or a binary logical operation (`BinaryLogicalOperation`).
236+
* a binary logical operation (`BinaryLogicalOperation`), or an
237+
* assignment (`Assignment`).
237238
*/
238239
class BinaryOperation extends Operation, @bin_op {
239240
/** Gets the left operand of this binary operation. */

csharp/ql/test/library-tests/linq/Linq2.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
import csharp
66

77
from BinaryOperation e
8+
where not e instanceof Assignment
89
select e, e.getAnOperand()

0 commit comments

Comments
 (0)