Skip to content

Commit 37e4db5

Browse files
committed
C#: Handle compound assignment operators in the dispatch logic (and assignable definition).
1 parent f030794 commit 37e4db5

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ module AssignableInternal {
315315
TAddressOfDefinition(AddressOfExpr aoe) or
316316
TPatternDefinition(TopLevelPatternDecl tlpd) or
317317
TAssignOperationDefinition(AssignOperation ao) {
318-
ao instanceof AssignCallOperation or
318+
ao instanceof AssignCallOperation and not ao instanceof CompoundAssignmentOperatorCall
319+
or
319320
ao instanceof AssignCoalesceExpr
320321
}
321322

csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ private module Internal {
9999
or
100100
ac instanceof AssignableWrite and isRead = false
101101
} or
102-
TDispatchOperatorCall(OperatorCall oc) { not oc.isLateBound() } or
102+
TDispatchOperatorCall(OperatorCall oc) {
103+
not oc.isLateBound() and
104+
not oc instanceof CompoundAssignmentOperatorCall
105+
} or
106+
TDispatchCompoundAssignmentOperatorCall(CompoundAssignmentOperatorCall caoc) or
103107
TDispatchReflectionCall(MethodCall mc, string name, Expr object, Expr qualifier, int args) {
104108
isReflectionCall(mc, name, object, qualifier, args)
105109
} or
@@ -886,6 +890,20 @@ private module Internal {
886890
override Operator getAStaticTarget() { result = this.getCall().getTarget() }
887891
}
888892

893+
private class DispatchCompoundAssignmentOperatorCall extends DispatchOverridableCall,
894+
TDispatchCompoundAssignmentOperatorCall
895+
{
896+
override CompoundAssignmentOperatorCall getCall() {
897+
this = TDispatchCompoundAssignmentOperatorCall(result)
898+
}
899+
900+
override Expr getArgument(int i) { result = this.getCall().getArgument(i) }
901+
902+
override Expr getQualifier() { result = this.getCall().getQualifier() }
903+
904+
override Operator getAStaticTarget() { result = this.getCall().getTarget() }
905+
}
906+
889907
/**
890908
* A call to an accessor.
891909
*

0 commit comments

Comments
 (0)