|
| 1 | +package b |
| 2 | + |
| 3 | +import "io" |
| 4 | + |
| 5 | +// unexportedReader is an unexported interface. |
| 6 | +type unexportedReader interface { |
| 7 | + Read([]byte) (int, error) |
| 8 | +} |
| 9 | + |
| 10 | +// ExportedWriter is an exported interface. |
| 11 | +type ExportedWriter interface { |
| 12 | + Write([]byte) (int, error) |
| 13 | +} |
| 14 | + |
| 15 | +// ExportedType is an exported struct type. |
| 16 | +type ExportedType struct{} |
| 17 | + |
| 18 | +// 1. Method with unexported arg type interface |
| 19 | +func (e *ExportedType) ReadAll(r unexportedReader) ([]byte, error) { // want "unexported interface 'unexportedReader' used as parameter in exported method 'ExportedType.ReadAll'" |
| 20 | + buf := make([]byte, 1024) |
| 21 | + _, err := r.Read(buf) |
| 22 | + return buf, err |
| 23 | +} |
| 24 | + |
| 25 | +// 2. Method with exported arg type interface |
| 26 | +func (e *ExportedType) WriteHello(w ExportedWriter) error { |
| 27 | + _, err := w.Write([]byte("hello")) |
| 28 | + return err |
| 29 | +} |
| 30 | + |
| 31 | +// 3. Method with unexported return type interface |
| 32 | +func (e *ExportedType) NewUnexportedReader() unexportedReader { // want "unexported interface 'unexportedReader' used as return value in exported method 'ExportedType.NewUnexportedReader'" |
| 33 | + return nil // stub |
| 34 | +} |
| 35 | + |
| 36 | +// 4. Method with exported return type interface |
| 37 | +func (e *ExportedType) NewWriter() ExportedWriter { |
| 38 | + return nil // stub |
| 39 | +} |
| 40 | + |
| 41 | +// 5. Method with both unexported arg and return type interface |
| 42 | +func (e *ExportedType) WrapReader(r unexportedReader) unexportedReader { // want "unexported interface 'unexportedReader' used as parameter in exported method 'ExportedType.WrapReader'" "unexported interface 'unexportedReader' used as return value in exported method 'ExportedType.WrapReader'" |
| 43 | + return r |
| 44 | +} |
| 45 | + |
| 46 | +// 6. Method with both exported arg and return type interface |
| 47 | +func (e *ExportedType) WrapWriter(w ExportedWriter) ExportedWriter { |
| 48 | + return w |
| 49 | +} |
| 50 | + |
| 51 | +// 7. Method with unexported arg type interface and exported return type interface |
| 52 | +func (e *ExportedType) PromoteReader(r unexportedReader) ExportedWriter { // want "unexported interface 'unexportedReader' used as parameter in exported method 'ExportedType.PromoteReader'" |
| 53 | + return nil // stub |
| 54 | +} |
| 55 | + |
| 56 | +// 8. Method with exported arg type interface and unexported return type interface |
| 57 | +func (e *ExportedType) DemoteWriter(w ExportedWriter) unexportedReader { // want "unexported interface 'unexportedReader' used as return value in exported method 'ExportedType.DemoteWriter'" |
| 58 | + return nil // stub |
| 59 | +} |
| 60 | + |
| 61 | +// 9. Method with external arg type interface (io.Writer) |
| 62 | +func (e *ExportedType) WriteToExternal(w io.Writer) error { |
| 63 | + _, err := w.Write([]byte("external")) |
| 64 | + return err |
| 65 | +} |
| 66 | + |
| 67 | +// 10. Method with external return type interface (io.Writer) |
| 68 | +func (e *ExportedType) NewExternalWriter() io.Writer { |
| 69 | + return nil // stub |
| 70 | +} |
| 71 | + |
| 72 | +// 11. Method with both external arg and return type interface (io.Writer) |
| 73 | +func (e *ExportedType) WrapExternalWriter(w io.Writer) io.Writer { |
| 74 | + return w |
| 75 | +} |
| 76 | + |
| 77 | +// 13. Method with any arg type |
| 78 | +func (e *ExportedType) Print(a any) { |
| 79 | +} |
| 80 | + |
| 81 | +// 14. Method with interface{} arg type |
| 82 | +func (e *ExportedType) Write(i interface{}) { |
| 83 | +} |
| 84 | + |
| 85 | +// 15. Method with error arg type |
| 86 | +func (e *ExportedType) Capture(err error) {} |
| 87 | + |
| 88 | +// 16. Method with no arg and no return type interface |
| 89 | +func (e *ExportedType) Ping() {} |
| 90 | + |
| 91 | +// 17. Method with primitive arg type |
| 92 | +func (e *ExportedType) AddOne(x int) int { |
| 93 | + return x + 1 |
| 94 | +} |
| 95 | + |
| 96 | +// 18. Method with primitive return type |
| 97 | +func (e *ExportedType) GetZero() int { |
| 98 | + return 0 |
| 99 | +} |
| 100 | + |
| 101 | +// 19. Method with both primitive arg and return type |
| 102 | +func (e *ExportedType) Double(x int) int { |
| 103 | + return x * 2 |
| 104 | +} |
0 commit comments