GoPLS Viewer

Home|gopls/go/analysis/passes/deepequalerrors/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 deepequalerrors checker.
6
7package a
8
9import (
10    "io"
11    "os"
12    "reflect"
13)
14
15type myError int
16
17func (myErrorError() string { return "" }
18
19func bad() error { return nil }
20
21type s1 struct {
22    s2 *s2
23    i  int
24}
25
26type myError2 error
27
28type s2 struct {
29    s1   *s1
30    errs []*myError2
31}
32
33func hasError() {
34    var e error
35    var m myError2
36    reflect.DeepEqual(bad(), e)           // want `avoid using reflect.DeepEqual with errors`
37    reflect.DeepEqual(io.EOFio.EOF)     // want `avoid using reflect.DeepEqual with errors`
38    reflect.DeepEqual(e, &e)              // want `avoid using reflect.DeepEqual with errors`
39    reflect.DeepEqual(em)               // want `avoid using reflect.DeepEqual with errors`
40    reflect.DeepEqual(es1{})            // want `avoid using reflect.DeepEqual with errors`
41    reflect.DeepEqual(e, [1]error{})      // want `avoid using reflect.DeepEqual with errors`
42    reflect.DeepEqual(e, map[error]int{}) // want `avoid using reflect.DeepEqual with errors`
43    reflect.DeepEqual(e, map[int]error{}) // want `avoid using reflect.DeepEqual with errors`
44    // We catch the next not because *os.PathError implements error, but because it contains
45    // a field Err of type error.
46    reflect.DeepEqual(&os.PathError{}, io.EOF// want `avoid using reflect.DeepEqual with errors`
47
48}
49
50func notHasError() {
51    reflect.ValueOf(4)                    // not reflect.DeepEqual
52    reflect.DeepEqual(34)               // not errors
53    reflect.DeepEqual(5io.EOF)          // only one error
54    reflect.DeepEqual(myError(1), io.EOF// not types that implement error
55}
56
MembersX
bad
s1.s2
notHasError
myError
s1.i
hasError.e
os
myError.Error
s1
myError2
s2
hasError.m
io
reflect
s2.s1
s2.errs
hasError
Members
X