github.com/jhump/golang-x-tools@v0.0.0-20220218190644-4958d6d39439/go/analysis/passes/assign/testdata/src/a/a.go.golden (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This file contains tests for the useless-assignment checker. 6 7 package testdata 8 9 import "math/rand" 10 11 type ST struct { 12 x int 13 l []int 14 } 15 16 func (s *ST) SetX(x int, ch chan int) { 17 // Accidental self-assignment; it should be "s.x = x" 18 // want "self-assignment of x to x" 19 // Another mistake 20 // want "self-assignment of s.x to s.x" 21 22 // want "self-assignment of s.l.0. to s.l.0." 23 24 // Bail on any potential side effects to avoid false positives 25 s.l[num()] = s.l[num()] 26 rng := rand.New(rand.NewSource(0)) 27 s.l[rng.Intn(len(s.l))] = s.l[rng.Intn(len(s.l))] 28 s.l[<-ch] = s.l[<-ch] 29 } 30 31 func num() int { return 2 }