diff --git a/testdata/modifies_value_receiver.go b/testdata/modifies_value_receiver.go index 11757c9b7..0d2fe44d0 100644 --- a/testdata/modifies_value_receiver.go +++ b/testdata/modifies_value_receiver.go @@ -47,3 +47,40 @@ func (this data) assignmentOperators() { this.num >>= 1 // MATCH /suspicious assignment to a by-value method receiver/ this.num <<= 1 // MATCH /suspicious assignment to a by-value method receiver/ } + +type rfoo struct { + CntP *int + Cnt int + rbar + RBar rbar + PRBar *rbar +} + +type rbar struct { + BCntP *int + BCnt int +} + +func (foo rfoo) increment() { + // these are detected + foo.Cnt++ // MATCH /suspicious assignment to a by-value method receiver/ + foo.BCnt++ // MATCH /suspicious assignment to a by-value method receiver/ + + // this one is only a another notation for foo.BCnt++ + foo.rbar.BCnt++ // MATCH /this one should be detected, no?/ + // this on + foo.RBar.BCnt++ // MATCH /this one should be detected, no?/ + + // here, we are updating the pointer of a non-pointer receiver + // it will lead to nothing, it should be detected, no ? + *foo.CntP++ // MATCH /what do we want for this one?/ + + // same here, it should be detected, no ? + *foo.rbar.BCntP++ // MATCH /what do we want for this one?/ + *foo.BCntP++ // MATCH /what do we want for this one?/ + + // these rely on pointers, they should not be detected, right? + *foo.RBar.BCntP++ // MATCH /what do we want for this one?/ + *foo.PRBar.BCntP++ // MATCH /what do we want for this one?/ + foo.PRBar.BCnt++ // MATCH /what do we want for this one?/ +}