github.com/serversong/goreporter@v0.0.0-20200325104552-3cfaf44fd178/linters/interfacer/testdata/files/results.go (about)

     1  package foo
     2  
     3  type Closer interface {
     4  	Close() error
     5  }
     6  
     7  type ReadCloser interface {
     8  	Closer
     9  	Read() (int, error)
    10  }
    11  
    12  func Results(rc ReadCloser) {
    13  	_, _ = rc.Read()
    14  	err := rc.Close()
    15  	println(err)
    16  }
    17  
    18  func ResultsWrong(rc ReadCloser) { // WARN rc can be Closer
    19  	err := rc.Close()
    20  	println(err)
    21  }
    22  
    23  type argBad struct{}
    24  
    25  func (a argBad) Read() (string, error) {
    26  	return "", nil
    27  }
    28  
    29  func (a argBad) Write() error {
    30  	return nil
    31  }
    32  
    33  func (a argBad) Close() int {
    34  	return 0
    35  }
    36  
    37  func ResultsMismatchNumber(a argBad) {
    38  	_ = a.Write()
    39  }
    40  
    41  func ResultsMismatchType(a argBad) {
    42  	s, _ := a.Read()
    43  	println(s)
    44  }
    45  
    46  func ResultsMismatchTypes(a, b argBad) {
    47  	r1, r2 := a.Close(), b.Close()
    48  	println(r1, r2)
    49  }