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 9, 2024
1 parent f94c9d7 commit e7ac41a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions testdata/modifies_value_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?/
}

0 comments on commit e7ac41a

Please sign in to comment.