modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/bug459.go (about) 1 // errorcheck 2 3 // Copyright 2012 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // Issue 3890: missing detection of init loop involving 8 // method calls in function bodies. 9 10 package flag 11 12 var commandLine = NewFlagSet() // ERROR "loop|depends upon itself" 13 14 type FlagSet struct { 15 } 16 17 func (f *FlagSet) failf(format string, a ...interface{}) { 18 f.usage() 19 } 20 21 func (f *FlagSet) usage() { 22 if f == commandLine { 23 panic(3) 24 } 25 } 26 27 func NewFlagSet() *FlagSet { 28 f := &FlagSet{} 29 f.setErrorHandling(true) 30 return f 31 } 32 33 func (f *FlagSet) setErrorHandling(b bool) { 34 f.failf("DIE") 35 }