C#: Handle compound assignment operators in the dispatch logic (and assignable definition).

This commit is contained in:
Michael Nebel
2026-04-22 15:43:53 +02:00
parent bdf0c8ff5a
commit e2fcaeb46a
2 changed files with 21 additions and 2 deletions

View File

@@ -315,7 +315,8 @@ module AssignableInternal {
TAddressOfDefinition(AddressOfExpr aoe) or
TPatternDefinition(TopLevelPatternDecl tlpd) or
TAssignOperationDefinition(AssignOperation ao) {
ao instanceof AssignCallOperation or
ao instanceof AssignCallOperation and not ao instanceof CompoundAssignmentOperatorCall
or
ao instanceof AssignCoalesceExpr
}

View File

@@ -99,7 +99,11 @@ private module Internal {
or
ac instanceof AssignableWrite and isRead = false
} or
TDispatchOperatorCall(OperatorCall oc) { not oc.isLateBound() } or
TDispatchOperatorCall(OperatorCall oc) {
not oc.isLateBound() and
not oc instanceof CompoundAssignmentOperatorCall
} or
TDispatchCompoundAssignmentOperatorCall(CompoundAssignmentOperatorCall caoc) or
TDispatchReflectionCall(MethodCall mc, string name, Expr object, Expr qualifier, int args) {
isReflectionCall(mc, name, object, qualifier, args)
} or
@@ -886,6 +890,20 @@ private module Internal {
override Operator getAStaticTarget() { result = this.getCall().getTarget() }
}
private class DispatchCompoundAssignmentOperatorCall extends DispatchOverridableCall,
TDispatchCompoundAssignmentOperatorCall
{
override CompoundAssignmentOperatorCall getCall() {
this = TDispatchCompoundAssignmentOperatorCall(result)
}
override Expr getArgument(int i) { result = this.getCall().getArgument(i) }
override Expr getQualifier() { result = this.getCall().getQualifier() }
override Operator getAStaticTarget() { result = this.getCall().getTarget() }
}
/**
* A call to an accessor.
*