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%2Ferrorsas%2Ferrorsas.go;fp=.config%2Fcoc%2Fextensions%2Fcoc-go-data%2Ftools%2Fpkg%2Fmod%2Fgolang.org%2Fx%2Ftools%40v0.0.0-20201028153306-37f0764111ff%2Fgo%2Fanalysis%2Fpasses%2Ferrorsas%2Ferrorsas.go;h=0000000000000000000000000000000000000000;hb=3ddadb3c98564791f0ac36cb39771d844a63dc91;hp=384f0255704da23110a0cc76528ed4e7bd82726a;hpb=5f797af6612ed10887189b47a1efc2f915586e59;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/errorsas/errorsas.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201028153306-37f0764111ff/go/analysis/passes/errorsas/errorsas.go deleted file mode 100644 index 384f0255..00000000 --- a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201028153306-37f0764111ff/go/analysis/passes/errorsas/errorsas.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2018 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. - -// The errorsas package defines an Analyzer that checks that the second argument to -// errors.As is a pointer to a type implementing error. -package errorsas - -import ( - "go/ast" - "go/types" - - "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/passes/inspect" - "golang.org/x/tools/go/ast/inspector" - "golang.org/x/tools/go/types/typeutil" -) - -const Doc = `report passing non-pointer or non-error values to errors.As - -The errorsas analysis reports calls to errors.As where the type -of the second argument is not a pointer to a type implementing error.` - -var Analyzer = &analysis.Analyzer{ - Name: "errorsas", - Doc: Doc, - Requires: []*analysis.Analyzer{inspect.Analyzer}, - Run: run, -} - -func run(pass *analysis.Pass) (interface{}, error) { - switch pass.Pkg.Path() { - case "errors", "errors_test": - // These packages know how to use their own APIs. - // Sometimes they are testing what happens to incorrect programs. - return nil, nil - } - - inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) - - nodeFilter := []ast.Node{ - (*ast.CallExpr)(nil), - } - inspect.Preorder(nodeFilter, func(n ast.Node) { - call := n.(*ast.CallExpr) - fn := typeutil.StaticCallee(pass.TypesInfo, call) - if fn == nil { - return // not a static call - } - if len(call.Args) < 2 { - return // not enough arguments, e.g. called with return values of another function - } - if fn.FullName() == "errors.As" && !pointerToInterfaceOrError(pass, call.Args[1]) { - pass.ReportRangef(call, "second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type") - } - }) - return nil, nil -} - -var errorType = types.Universe.Lookup("error").Type().Underlying().(*types.Interface) - -// pointerToInterfaceOrError reports whether the type of e is a pointer to an interface or a type implementing error, -// or is the empty interface. -func pointerToInterfaceOrError(pass *analysis.Pass, e ast.Expr) bool { - t := pass.TypesInfo.Types[e].Type - if it, ok := t.Underlying().(*types.Interface); ok && it.NumMethods() == 0 { - return true - } - pt, ok := t.Underlying().(*types.Pointer) - if !ok { - return false - } - _, ok = pt.Elem().Underlying().(*types.Interface) - return ok || types.Implements(pt.Elem(), errorType) -}