diff --git a/testdata/modifies_value_receiver.go b/testdata/modifies_value_receiver.go index 11757c9b7..d09b3b7b3 100644 --- a/testdata/modifies_value_receiver.go +++ b/testdata/modifies_value_receiver.go @@ -47,3 +47,48 @@ 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 + *rquz + RBar rbar + PRBar *rbar +} + +type rbar struct { + BCntP *int + BCnt int +} + +type rquz struct { + QCnt 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 + // right now it's not reported, shouldn't it ? + *foo.CntP++ // MATCH /what do we want for this one?/ + + // here rquz is a pointer struct, it should not be detected, right ? + foo.QCnt++ // MATCH /we shouldn't report this one, right?/ + + // 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?/ +}