honnef.co/go/tools@v0.5.0-0.dev.0.20240520180541-dcae280a5e87/staticcheck/sa1023/testdata/src/example.com/CheckWriterBufferModified/CheckWriterBufferModified.go (about)

     1  package pkg
     2  
     3  type T1 struct{}
     4  type T2 struct{}
     5  type T3 struct{}
     6  type T4 struct{}
     7  type T5 struct{}
     8  type T6 struct{}
     9  type T7 struct{}
    10  
    11  type Bytes []byte
    12  
    13  type AliasByte = byte
    14  type AliasByteSlice = []byte
    15  type AliasInt = int
    16  type AliasError = error
    17  
    18  func (T1) Write(b []byte) (int, error) {
    19  	b = append(b, '\n') //@ diag(`io.Writer.Write must not modify the provided buffer`)
    20  	_ = b
    21  	return 0, nil
    22  }
    23  
    24  func (T2) Write(b []byte) (int, error) {
    25  	b[0] = 0 //@ diag(`io.Writer.Write must not modify the provided buffer`)
    26  	return 0, nil
    27  }
    28  
    29  func (T3) Write(b []byte) string {
    30  	b[0] = 0
    31  	return ""
    32  }
    33  
    34  func (T4) Write(b []byte, r byte) (int, error) {
    35  	b[0] = r
    36  	return 0, nil
    37  }
    38  
    39  func (T5) Write(b []AliasByte) (int, error) {
    40  	b[0] = 0 //@ diag(`io.Writer.Write must not modify the provided buffer`)
    41  	return 0, nil
    42  }
    43  
    44  func (T6) Write(b AliasByteSlice) (AliasInt, AliasError) {
    45  	b[0] = 0 //@ diag(`io.Writer.Write must not modify the provided buffer`)
    46  	return 0, nil
    47  }
    48  
    49  func (T7) Write(b Bytes) (int, error) {
    50  	b[0] = 0
    51  	return 0, nil
    52  }