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

     1  package pkg
     2  
     3  func fn1() {
     4  	var x int
     5  	x = gen() // MATCH /this value of x is never used/
     6  	x = gen()
     7  	println(x)
     8  
     9  	var y int
    10  	if true {
    11  		y = gen() // MATCH /this value of y is never used/
    12  	}
    13  	y = gen()
    14  	println(y)
    15  }
    16  
    17  func gen() int {
    18  	println() // make it unpure
    19  	return 0
    20  }
    21  
    22  func fn2() {
    23  	x, y := gen(), gen()
    24  	x, y = gen(), gen()
    25  	println(x, y)
    26  }
    27  
    28  // MATCH:23 /this value of x is never used/
    29  // MATCH:23 /this value of y is never used/
    30  
    31  func fn3() {
    32  	x := uint32(0)
    33  	if true {
    34  		x = 1
    35  	} else {
    36  		x = 2
    37  	}
    38  	println(x)
    39  }
    40  
    41  func gen2() (int, int) {
    42  	println()
    43  	return 0, 0
    44  }
    45  
    46  func fn4() {
    47  	x, y := gen2() // MATCH /this value of x is never used/
    48  	println(y)
    49  	x, y = gen2()
    50  	x, y = gen2()
    51  	println(x, y)
    52  }
    53  
    54  // MATCH:49 /this value of x is never used/
    55  // MATCH:49 /this value of y is never used/
    56  
    57  func fn5(m map[string]string) {
    58  	v, ok := m[""]
    59  	v, ok = m[""]
    60  	println(v, ok)
    61  }
    62  
    63  // MATCH:58 /this value of v is never used/
    64  // MATCH:58 /this value of ok is never used/
    65  
    66  func fn6() {
    67  	x := gen()
    68  	// Do not report variables if they've been assigned to the blank identifier
    69  	_ = x
    70  }