Debian Codegraph @

go/analysis/passes/errorsas/testdata/src/a/a.go

raw symbols SCIP
1 // Copyright 2019 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 // This file contains tests for the errorsas checker.
6
7 package a
8
9 import "errors"
10
11 type myError int
12
13 func (myError) Error() string { return "" }
14
15 func perr() *error { return nil }
16
17 type iface interface {
18 m()
19 }
20
21 func two() (error, interface{}) { return nil, nil }
22
23 func _() {
24 var (
25 e error
26 m myError
27 i int
28 f iface
29 ei interface{}
30 )
31 errors.As(nil, &e) // want `second argument to errors.As should not be \*error`
32 errors.As(nil, &m) // *T where T implements error
33 errors.As(nil, &f) // *interface
34 errors.As(nil, perr()) // want `second argument to errors.As should not be \*error`
35 errors.As(nil, ei) // empty interface
36
37 errors.As(nil, nil) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
38 errors.As(nil, e) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
39 errors.As(nil, m) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
40 errors.As(nil, f) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
41 errors.As(nil, &i) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
42 errors.As(two())
43 }