Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201028153306-37f0764111ff / go / analysis / passes / deepequalerrors / testdata / src / a / a.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201028153306-37f0764111ff/go/analysis/passes/deepequalerrors/testdata/src/a/a.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201028153306-37f0764111ff/go/analysis/passes/deepequalerrors/testdata/src/a/a.go
new file mode 100644 (file)
index 0000000..f972c9b
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file contains tests for the deepequalerrors checker.
+
+package a
+
+import (
+       "io"
+       "os"
+       "reflect"
+)
+
+type myError int
+
+func (myError) Error() string { return "" }
+
+func bad() error { return nil }
+
+type s1 struct {
+       s2 *s2
+       i  int
+}
+
+type myError2 error
+
+type s2 struct {
+       s1   *s1
+       errs []*myError2
+}
+
+func hasError() {
+       var e error
+       var m myError2
+       reflect.DeepEqual(bad(), e)           // want `avoid using reflect.DeepEqual with errors`
+       reflect.DeepEqual(io.EOF, io.EOF)     // want `avoid using reflect.DeepEqual with errors`
+       reflect.DeepEqual(e, &e)              // want `avoid using reflect.DeepEqual with errors`
+       reflect.DeepEqual(e, m)               // want `avoid using reflect.DeepEqual with errors`
+       reflect.DeepEqual(e, s1{})            // want `avoid using reflect.DeepEqual with errors`
+       reflect.DeepEqual(e, [1]error{})      // want `avoid using reflect.DeepEqual with errors`
+       reflect.DeepEqual(e, map[error]int{}) // want `avoid using reflect.DeepEqual with errors`
+       reflect.DeepEqual(e, map[int]error{}) // want `avoid using reflect.DeepEqual with errors`
+       // We catch the next not because *os.PathError implements error, but because it contains
+       // a field Err of type error.
+       reflect.DeepEqual(&os.PathError{}, io.EOF) // want `avoid using reflect.DeepEqual with errors`
+
+}
+
+func notHasError() {
+       reflect.ValueOf(4)                    // not reflect.DeepEqual
+       reflect.DeepEqual(3, 4)               // not errors
+       reflect.DeepEqual(5, io.EOF)          // only one error
+       reflect.DeepEqual(myError(1), io.EOF) // not types that implement error
+}