X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fcoc-go-data%2Ftools%2Fpkg%2Fmod%2Fgolang.org%2Fx%2Ftools%40v0.0.0-20201028153306-37f0764111ff%2Fgo%2Fanalysis%2Fpasses%2Fdeepequalerrors%2Ftestdata%2Fsrc%2Fa%2Fa.go;fp=.config%2Fcoc%2Fextensions%2Fcoc-go-data%2Ftools%2Fpkg%2Fmod%2Fgolang.org%2Fx%2Ftools%40v0.0.0-20201028153306-37f0764111ff%2Fgo%2Fanalysis%2Fpasses%2Fdeepequalerrors%2Ftestdata%2Fsrc%2Fa%2Fa.go;h=f972c9bf0f84d10a290d77c154e085bc38befd4b;hb=4d07c77cf4d78cab8639e13ddc3c22495e585b0b;hp=0000000000000000000000000000000000000000;hpb=b3950616b54221c40a7dab9099bda675007e5b6e;p=dotfiles%2F.git 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 index 00000000..f972c9bf --- /dev/null +++ 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 @@ -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 +}