github.com/serversong/goreporter@v0.0.0-20200325104552-3cfaf44fd178/linters/staticcheck/testdata/CheckIneffecitiveFieldAssignments.go (about)

     1  package pkg
     2  
     3  import "fmt"
     4  
     5  type T struct {
     6  	X int
     7  }
     8  
     9  func (t T) Fn1() {
    10  	t.X = 1 // MATCH /ineffective assignment to field X/
    11  }
    12  
    13  func (t T) Fn2() {
    14  	t.X = 1
    15  	fmt.Println(t)
    16  }
    17  
    18  func (t T) Fn3() {
    19  	t.X = 1
    20  	t.Fn4()
    21  }
    22  
    23  func (t T) Fn4() {
    24  	t.X = 1
    25  	println(t.X)
    26  }
    27  
    28  func (t T) Fn5() {
    29  	fn1(&t)
    30  	t.X = 1
    31  }
    32  
    33  func (t *T) Fn6() {
    34  	t.X = 1
    35  }
    36  
    37  func fn1(*T) {}