github.com/serversong/goreporter@v0.0.0-20200325104552-3cfaf44fd178/linters/staticcheck/testdata/CheckCyclicFinalizer.go (about) 1 package pkg 2 3 import ( 4 "fmt" 5 "runtime" 6 ) 7 8 func fn() { 9 var x *int 10 foo := func(y *int) { fmt.Println(x) } 11 runtime.SetFinalizer(x, foo) 12 runtime.SetFinalizer(x, nil) 13 runtime.SetFinalizer(x, func(_ *int) { 14 fmt.Println(x) 15 }) 16 17 foo = func(y *int) { fmt.Println(y) } 18 runtime.SetFinalizer(x, foo) 19 runtime.SetFinalizer(x, func(y *int) { 20 fmt.Println(y) 21 }) 22 } 23 24 // MATCH:11 /the finalizer closes over the object, preventing the finalizer from ever running \(at .+:10:9/ 25 // MATCH:13 /the finalizer closes over the object, preventing the finalizer from ever running \(at .+:13:26/