GoPLS Viewer

Home|gopls/go/analysis/passes/errorsas/testdata/src/a/a.go
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
7package a
8
9import "errors"
10
11type myError int
12
13func (myErrorError() string { return "" }
14
15func perr() *error { return nil }
16
17type iface interface {
18    m()
19}
20
21func two() (error, interface{}) { return nilnil }
22
23func _() {
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 implemements error
33    errors.As(nil, &f)     // *interface
34    errors.As(nilperr()) // want `second argument to errors.As should not be \*error`
35    errors.As(nilei)     //  empty interface
36
37    errors.As(nilnil// 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(nile)   // 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(nilm)   // 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(nilf)   // 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}
44
MembersX
errors
two
_
myError
myError.Error
perr
iface
_.e
_.m
_.i
_.f
Members
X