| 1 | // Copyright 2010 The Go Authors. All rights reserved. |
|---|---|
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package a |
| 6 | |
| 7 | import ( |
| 8 | "encoding/xml" |
| 9 | "fmt" |
| 10 | "io" |
| 11 | ) |
| 12 | |
| 13 | type T int |
| 14 | |
| 15 | func (T) Scan(x fmt.ScanState, c byte) {} // want `should have signature Scan\(fmt\.ScanState, rune\) error` |
| 16 | |
| 17 | func (T) Format(fmt.State, byte) {} // want `should have signature Format\(fmt.State, rune\)` |
| 18 | |
| 19 | type U int |
| 20 | |
| 21 | func (U) Format(byte) {} // no error: first parameter must be fmt.State to trigger check |
| 22 | |
| 23 | func (U) GobDecode() {} // want `should have signature GobDecode\(\[\]byte\) error` |
| 24 | |
| 25 | // Test rendering of type names such as xml.Encoder in diagnostic. |
| 26 | func (U) MarshalXML(*xml.Encoder) {} // want `method MarshalXML\(\*xml.Encoder\) should...` |
| 27 | |
| 28 | func (U) UnmarshalXML(*xml.Decoder, xml.StartElement) error { // no error: signature matches xml.Unmarshaler |
| 29 | return nil |
| 30 | } |
| 31 | |
| 32 | func (U) WriteTo(w io.Writer) {} // want `method WriteTo\(w io.Writer\) should have signature WriteTo\(io.Writer\) \(int64, error\)` |
| 33 | |
| 34 | func (T) WriteTo(w io.Writer, more, args int) {} // ok - clearly not io.WriterTo |
| 35 | |
| 36 | type I interface { |
| 37 | ReadByte() byte // want `should have signature ReadByte\(\) \(byte, error\)` |
| 38 | } |
| 39 | |
| 40 | type V int // V does not implement error. |
| 41 | |
| 42 | func (V) As() T { return 0 } // ok - V is not an error |
| 43 | func (V) Is() bool { return false } // ok - V is not an error |
| 44 | func (V) Unwrap() int { return 0 } // ok - V is not an error |
| 45 | |
| 46 | type E int |
| 47 | |
| 48 | func (E) Error() string { return "" } // E implements error. |
| 49 | |
| 50 | func (E) As() {} // want `method As\(\) should have signature As\((any|interface\{\})\) bool` |
| 51 | func (E) Is() {} // want `method Is\(\) should have signature Is\(error\) bool` |
| 52 | func (E) Unwrap() {} // want `method Unwrap\(\) should have signature Unwrap\(\) error or Unwrap\(\) \[\]error` |
| 53 | |
| 54 | type F int |
| 55 | |
| 56 | func (F) Error() string { return "" } // Both F and *F implement error. |
| 57 | |
| 58 | func (*F) As() {} // want `method As\(\) should have signature As\((any|interface\{\})\) bool` |
| 59 | func (*F) Is() {} // want `method Is\(\) should have signature Is\(error\) bool` |
| 60 | func (*F) Unwrap() {} // want `method Unwrap\(\) should have signature Unwrap\(\) error or Unwrap\(\) \[\]error` |
| 61 | |
| 62 | type G int |
| 63 | |
| 64 | func (G) As(interface{}) bool // ok |
| 65 | |
| 66 | type W int |
| 67 | |
| 68 | func (W) Error() string { return "" } |
| 69 | func (W) Unwrap() error { return nil } // ok |
| 70 | |
| 71 | type M int |
| 72 | |
| 73 | func (M) Error() string { return "" } |
| 74 | func (M) Unwrap() []error { return nil } // ok |
| 75 |
Members