Skip to content

Commit

Permalink
PoC of what is not detected yet
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoVeille committed Dec 8, 2024
1 parent f94c9d7 commit 917829d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions testdata/modifies_value_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?/
}

0 comments on commit 917829d

Please sign in to comment.