22package testdata
33
44import (
5+ "bytes"
6+ "go/token"
57 "io"
8+ "net/http"
9+ "os"
610 "unsafe"
711)
812
@@ -24,6 +28,26 @@ func anonymousStructPtr() (*struct{ ID string }, error) {
2428 return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
2529}
2630
31+ func unsafePtr () (unsafe.Pointer , error ) {
32+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
33+ }
34+
35+ func uintPtr () (uintptr , error ) {
36+ return 0 , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
37+ }
38+
39+ func uintPtr0b () (uintptr , error ) {
40+ return 0b0 , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
41+ }
42+
43+ func uintPtr0x () (uintptr , error ) {
44+ return 0x00 , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
45+ }
46+
47+ func uintPtr0o () (uintptr , error ) {
48+ return 0o000 , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
49+ }
50+
2751func chBi () (chan int , error ) {
2852 return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
2953}
@@ -48,6 +72,10 @@ func iface() (interface{}, error) {
4872 return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
4973}
5074
75+ func anyType () (any , error ) {
76+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
77+ }
78+
5179func m1 () (map [int ]int , error ) {
5280 return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
5381}
@@ -56,6 +84,12 @@ func m2() (map[int]*User, error) {
5684 return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
5785}
5886
87+ type mapAlias = map [int ]* User
88+
89+ func m3 () (mapAlias , error ) {
90+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
91+ }
92+
5993type Storage struct {}
6094
6195func (s * Storage ) GetUser () (* User , error ) {
@@ -119,6 +153,39 @@ func deeplyNested() {
119153 }
120154}
121155
156+ type MyError interface {
157+ error
158+ Code () string
159+ }
160+
161+ func myError () (* User , MyError ) {
162+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
163+ }
164+
165+ // Types.
166+
167+ func structPtrTypeExtPkg () (* os.File , error ) {
168+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
169+ }
170+
171+ func primitivePtrTypeExtPkg () (* token.Token , error ) {
172+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
173+ }
174+
175+ func funcTypeExtPkg () (http.HandlerFunc , error ) {
176+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
177+ }
178+
179+ func ifaceTypeExtPkg () (io.Closer , error ) {
180+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
181+ }
182+
183+ type closerAlias = io.Closer
184+
185+ func ifaceTypeAliasedExtPkg () (closerAlias , error ) {
186+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
187+ }
188+
122189type (
123190 StructPtrType * User
124191 PrimitivePtrType * int
@@ -147,21 +214,93 @@ func ifaceType() (Checker, error) {
147214 return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
148215}
149216
217+ type checkerAlias = Checker
218+
219+ func ifaceTypeAliased () (checkerAlias , error ) {
220+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
221+ }
222+
223+ type (
224+ IntegerType int
225+ PtrIntegerType * IntegerType
226+ )
227+
228+ func ptrIntegerType () (PtrIntegerType , error ) {
229+ return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
230+ }
231+
232+ // Not checked at all.
233+
150234func withoutArgs () {}
151235func withoutError1 () * User { return nil }
152236func withoutError2 () (* User , * User ) { return nil , nil }
153237func withoutError3 () (* User , * User , * User ) { return nil , nil , nil }
154238func withoutError4 () (* User , * User , * User , * User ) { return nil , nil , nil , nil }
155239
156- // Unsupported.
157-
158240func invalidOrder () (error , * User ) { return nil , nil }
159241func withError3rd () (* User , bool , error ) { return nil , false , nil }
160242func withError4th () (* User , * User , * User , error ) { return nil , nil , nil , nil }
161- func unsafePtr () (unsafe.Pointer , error ) { return nil , nil }
162- func uintPtr () (uintptr , error ) { return 0 , nil }
163- func slice () ([]int , error ) { return nil , nil }
164- func ifaceExtPkg () (io.Closer , error ) { return nil , nil }
243+
244+ func slice () ([]int , error ) { return nil , nil }
245+
246+ func strNil () (string , error ) { return "nil" , nil }
247+ func strEmpty () (string , error ) { return "" , nil }
248+
249+ // Valid.
250+
251+ func primitivePtrTypeValid () (* int , error ) {
252+ if false {
253+ return nil , io .EOF
254+ }
255+ return new (int ), nil
256+ }
257+
258+ func structPtrTypeValid () (* User , error ) {
259+ if false {
260+ return nil , io .EOF
261+ }
262+ return new (User ), nil
263+ }
264+
265+ func unsafePtrValid () (unsafe.Pointer , error ) {
266+ if false {
267+ return nil , io .EOF
268+ }
269+ var i int
270+ return unsafe .Pointer (& i ), nil
271+ }
272+
273+ func uintPtrValid () (uintptr , error ) {
274+ if false {
275+ return 0 , io .EOF
276+ }
277+ return 0xc82000c290 , nil
278+ }
279+
280+ func channelTypeValid () (ChannelType , error ) {
281+ if false {
282+ return nil , io .EOF
283+ }
284+ return make (ChannelType ), nil
285+ }
286+
287+ func funcTypeValid () (FuncType , error ) {
288+ if false {
289+ return nil , io .EOF
290+ }
291+ return func (i int ) int {
292+ return 0
293+ }, nil
294+ }
295+
296+ func ifaceTypeValid () (io.Reader , error ) {
297+ if false {
298+ return nil , io .EOF
299+ }
300+ return new (bytes.Buffer ), nil
301+ }
302+
303+ // Unsupported.
165304
166305func implicitNil1 () (* User , error ) {
167306 err := (error )(nil )
0 commit comments