Rémy Oudompheng | 0b2ca9e | 2012-10-07 00:52:40 +0200 | [diff] [blame] | 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 | |
Rémy Oudompheng | 004dd3d7 | 2013-06-20 08:21:14 +0200 | [diff] [blame] | 12 | var commandLine = NewFlagSet() // ERROR "loop|depends upon itself" |
Rémy Oudompheng | 0b2ca9e | 2012-10-07 00:52:40 +0200 | [diff] [blame] | 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 | } |