Skip to content

Commit d8de1e3

Browse files
committed
FIXUP of assign operation implementation.
1 parent ab63949 commit d8de1e3

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

csharp/ql/lib/semmle/code/csharp/Assignable.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ module AssignableInternal {
292292
newtype TAssignableDefinition =
293293
TAssignmentDefinition(Assignment a) {
294294
not a.getLValue() instanceof TupleExpr and
295-
not a instanceof AssignOperation
295+
not a instanceof AssignCompoundOperation and
296+
not a instanceof AssignCoalesceExpr
296297
} or
297298
TTupleAssignmentDefinition(AssignExpr ae, Expr leaf) { tupleAssignmentDefinition(ae, leaf) } or
298299
TOutRefDefinition(AssignableAccess aa) {
@@ -317,7 +318,10 @@ module AssignableInternal {
317318
} or
318319
TAddressOfDefinition(AddressOfExpr aoe) or
319320
TPatternDefinition(TopLevelPatternDecl tlpd) or
320-
TAssignOperationDefinition(AssignOperation ao)
321+
TAssignOperationDefinition(AssignOperation ao) {
322+
ao instanceof AssignCompoundOperation or
323+
ao instanceof AssignCoalesceExpr
324+
}
321325

322326
/**
323327
* Gets the source expression assigned in tuple definition `def`, if any.

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class AssignExpr extends Assignment, @simple_assign_expr {
6363
* (`AssignArithmeticOperation`), a bitwise assignment operation or
6464
* (`AssignBitwiseOperation`).
6565
*/
66-
class AssignOperation extends Assignment, OperatorCall, @assign_op_expr {
66+
class AssignOperation extends Assignment, @assign_op_expr {
6767
override string getOperator() { none() }
6868

6969
/**
@@ -79,14 +79,21 @@ class AssignOperation extends Assignment, OperatorCall, @assign_op_expr {
7979
override string toString() { result = "... " + this.getOperator() + " ..." }
8080
}
8181

82+
/**
83+
* An assignment operation that corresponds to an operator call, for example `x += y` corresponds to `x = x + y`.
84+
*/
85+
class AssignCompoundOperation extends AssignOperation, OperatorCall, @assign_op_call_expr {
86+
override string toString() { result = "... " + this.getOperator() + " ..." }
87+
}
88+
8289
/**
8390
* An arithmetic assignment operation. Either an addition assignment operation
8491
* (`AssignAddExpr`), a subtraction assignment operation (`AssignSubExpr`), a
8592
* multiplication assignment operation (`AssignMulExpr`), a division assignment
8693
* operation (`AssignDivExpr`), or a remainder assignment operation
8794
* (`AssignRemExpr`).
8895
*/
89-
class AssignArithmeticOperation extends AssignOperation, @assign_arith_expr { }
96+
class AssignArithmeticOperation extends AssignCompoundOperation, @assign_arith_expr { }
9097

9198
/**
9299
* An addition assignment operation, for example `x += y`.
@@ -142,7 +149,7 @@ class AssignRemExpr extends AssignArithmeticOperation, @assign_rem_expr {
142149
* operation (`AssignRightShiftExpr`), or an unsigned right-shift assignment
143150
* operation (`AssignUnsignedRightShiftExpr`).
144151
*/
145-
class AssignBitwiseOperation extends AssignOperation, @assign_bitwise_expr { }
152+
class AssignBitwiseOperation extends AssignCompoundOperation, @assign_bitwise_expr { }
146153

147154
/**
148155
* A bitwise-and assignment operation, for example `x &= y`.
@@ -207,7 +214,7 @@ deprecated class AssignUnsighedRightShiftExpr = AssignUnsignedRightShiftExpr;
207214
* An event assignment. Either an event addition (`AddEventExpr`) or an event
208215
* removal (`RemoveEventExpr`).
209216
*/
210-
class AddOrRemoveEventExpr extends Assignment, @assign_event_expr {
217+
class AddOrRemoveEventExpr extends AssignOperation, @assign_event_expr {
211218
override string getOperator() { none() }
212219

213220
/** Gets the event targeted by this event assignment. */

0 commit comments

Comments
 (0)