2
2
package testdata
3
3
4
4
import (
5
+ "bytes"
6
+ "go/token"
5
7
"io"
8
+ "net/http"
9
+ "os"
6
10
"unsafe"
7
11
)
8
12
@@ -24,6 +28,26 @@ func anonymousStructPtr() (*struct{ ID string }, error) {
24
28
return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
25
29
}
26
30
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
+
27
51
func chBi () (chan int , error ) {
28
52
return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
29
53
}
@@ -48,6 +72,10 @@ func iface() (interface{}, error) {
48
72
return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
49
73
}
50
74
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
+
51
79
func m1 () (map [int ]int , error ) {
52
80
return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
53
81
}
@@ -56,6 +84,12 @@ func m2() (map[int]*User, error) {
56
84
return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
57
85
}
58
86
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
+
59
93
type Storage struct {}
60
94
61
95
func (s * Storage ) GetUser () (* User , error ) {
@@ -119,6 +153,39 @@ func deeplyNested() {
119
153
}
120
154
}
121
155
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
+
122
189
type (
123
190
StructPtrType * User
124
191
PrimitivePtrType * int
@@ -147,21 +214,93 @@ func ifaceType() (Checker, error) {
147
214
return nil , nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
148
215
}
149
216
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
+
150
234
func withoutArgs () {}
151
235
func withoutError1 () * User { return nil }
152
236
func withoutError2 () (* User , * User ) { return nil , nil }
153
237
func withoutError3 () (* User , * User , * User ) { return nil , nil , nil }
154
238
func withoutError4 () (* User , * User , * User , * User ) { return nil , nil , nil , nil }
155
239
156
- // Unsupported.
157
-
158
240
func invalidOrder () (error , * User ) { return nil , nil }
159
241
func withError3rd () (* User , bool , error ) { return nil , false , nil }
160
242
func 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.
165
304
166
305
func implicitNil1 () (* User , error ) {
167
306
err := (error )(nil )
0 commit comments