1package foo 2 3type Reader interface { 4 Read([]byte) (int, error) 5} 6 7type Closer interface { 8 Close() error 9} 10 11type ReadCloser interface { 12 Reader 13 Closer 14} 15 16func CompareNil(rc ReadCloser) { // WARN rc can be Closer 17 if rc != nil { 18 rc.Close() 19 } 20} 21 22func CompareIface(rc ReadCloser) { // WARN rc can be Closer 23 if rc != ReadCloser(nil) { 24 rc.Close() 25 } 26} 27 28func CompareIfaceDiff(rc ReadCloser) { // WARN rc can be Closer 29 if rc != Reader(nil) { 30 rc.Close() 31 } 32} 33 34type mint int 35 36func (m mint) Close() error { 37 return nil 38} 39 40func CompareStruct(m mint) { // WARN m can be Closer 41 if m != mint(3) { 42 m.Close() 43 } 44} 45 46func CompareStructVar(m mint) { // WARN m can be Closer 47 m2 := mint(2) 48 if m == m2 { 49 m.Close() 50 } 51} 52 53func CompareLit(m mint) { 54 if m != 3 { 55 m.Close() 56 } 57} 58