golang.org/x/tools@v0.21.0/go/analysis/passes/copylock/testdata/src/a/issue61678.go (about) 1 package a 2 3 import "sync" 4 5 // These examples are taken from golang/go#61678, modified so that A and B 6 // contain a mutex. 7 8 type A struct { 9 a A 10 mu sync.Mutex 11 } 12 13 type B struct { 14 a A 15 b B 16 mu sync.Mutex 17 } 18 19 func okay(x A) {} 20 func sure() { var x A; nop(x) } 21 22 var fine B 23 24 func what(x B) {} // want `passes lock by value` 25 func bad() { var x B; nop(x) } // want `copies lock value` 26 func good() { nop(B{}) } 27 func stillgood() { nop(B{b: B{b: B{b: B{}}}}) } 28 func nope() { nop(B{}.b) } // want `copies lock value` 29 30 func nop(any) {} // only used to get around unused variable errors