github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/staticcheck/sa4005/testdata/src/example.com/CheckIneffectiveFieldAssignments/issue141.go (about)

     1  package pkg
     2  
     3  import "fmt"
     4  
     5  // T is t
     6  type T struct {
     7  	X bool
     8  	F string
     9  }
    10  
    11  // Modify modifies T.F to say modified, then calls EchoF.
    12  func (t T) Modify() {
    13  	if t.X {
    14  		t.X, t.F = true, "modified"
    15  	}
    16  	t.EchoF()
    17  }
    18  
    19  // EchoF prints F.
    20  func (t T) EchoF() {
    21  	fmt.Println(t.F)
    22  }
    23  
    24  func main() {
    25  	t := T{X: true, F: "original"}
    26  
    27  	t.EchoF()  // output: original
    28  	t.Modify() // output: modified
    29  	t.EchoF()  // output: original
    30  }