From f1b4bd93c9465ac3d4edf2a53caf28cd21f846aa Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Sat, 3 Nov 2018 13:45:46 +0300 Subject: [PATCH] go/ssa: fix vet issues The new go/analysis/cmd/vet tool found a few issues. Fix them by explicitly ignoring results where needed and renaming examples in accordance to package testing's guidelines to make them appear on the godoc pages. This change doesn't touch go/ssa/interp/external.go because the possible misuse of package unsafe there looks intentional. Change-Id: Id63109e3797818a5e869fe8ed1bc1476959541f2 Reviewed-on: https://go-review.googlesource.com/c/147297 Run-TryBot: Brad Fitzpatrick Reviewed-by: Alan Donovan --- go/ssa/example_test.go | 6 +++--- go/ssa/sanity.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go/ssa/example_test.go b/go/ssa/example_test.go index c33b6d62..de5ed5e1 100644 --- a/go/ssa/example_test.go +++ b/go/ssa/example_test.go @@ -49,7 +49,7 @@ func main() { // with similar functionality. It is located at // golang.org/x/tools/cmd/ssadump. // -func ExampleBuildPackage() { +func Example_buildPackage() { // Parse the source files. fset := token.NewFileSet() f, err := parser.ParseFile(fset, "hello.go", hello, parser.ParseComments) @@ -117,7 +117,7 @@ func ExampleBuildPackage() { // This example builds SSA code for a set of packages using the // x/tools/go/packages API. This is what you would typically use for a // analysis capable of operating on a single package. -func ExampleLoadPackages() { +func Example_loadPackages() { // Load, parse, and type-check the initial packages. cfg := &packages.Config{Mode: packages.LoadSyntax} initial, err := packages.Load(cfg, "fmt", "net/http") @@ -147,7 +147,7 @@ func ExampleLoadPackages() { // This example builds SSA code for a set of packages plus all their dependencies, // using the x/tools/go/packages API. // This is what you'd typically use for a whole-program analysis. -func ExampleLoadWholeProgram() { +func Example_loadWholeProgram() { // Load, parse, and type-check the whole program. cfg := packages.Config{Mode: packages.LoadAllSyntax} initial, err := packages.Load(&cfg, "fmt", "net/http") diff --git a/go/ssa/sanity.go b/go/ssa/sanity.go index 6eb64328..0a7abc5e 100644 --- a/go/ssa/sanity.go +++ b/go/ssa/sanity.go @@ -408,8 +408,8 @@ func (s *sanity) checkFunction(fn *Function) bool { s.errorf("nil Prog") } - fn.String() // must not crash - fn.RelString(fn.pkg()) // must not crash + _ = fn.String() // must not crash + _ = fn.RelString(fn.pkg()) // must not crash // All functions have a package, except delegates (which are // shared across packages, or duplicated as weak symbols in a @@ -499,7 +499,7 @@ func sanityCheckPackage(pkg *Package) { if pkg.Pkg == nil { panic(fmt.Sprintf("Package %s has no Object", pkg)) } - pkg.String() // must not crash + _ = pkg.String() // must not crash for name, mem := range pkg.Members { if name != mem.Name() {