go/analysis/passes/tests: don't warn about missing method for each type

Only warn if the method is missing for all types.

Fixes golang/go#30971

Change-Id: I94169ad3266f68ca20378a8dc5538aed2541a773
Reviewed-on: https://go-review.googlesource.com/c/tools/+/168803
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Ian Lance Taylor 2019-03-22 07:22:32 -07:00
parent e250d351ec
commit 6aabc1ca79
2 changed files with 8 additions and 4 deletions

View File

@ -1,10 +1,14 @@
package b_x_test package b_x_test
import "b" import (
"a"
"b"
)
func ExampleFoo_F() { func ExampleFoo_F() {
var x b.Foo var x b.Foo
x.F() x.F()
a.Foo()
} }
func ExampleFoo_G() { // want "ExampleFoo_G refers to unknown field or method: Foo.G" func ExampleFoo_G() { // want "ExampleFoo_G refers to unknown field or method: Foo.G"

View File

@ -153,9 +153,9 @@ func checkExample(pass *analysis.Pass, fn *ast.FuncDecl) {
if obj, _, _ := types.LookupFieldOrMethod(obj.Type(), true, obj.Pkg(), mmbr); obj != nil { if obj, _, _ := types.LookupFieldOrMethod(obj.Type(), true, obj.Pkg(), mmbr); obj != nil {
found = true found = true
} }
if !found { }
pass.Reportf(fn.Pos(), "%s refers to unknown field or method: %s.%s", fnName, ident, mmbr) if !found {
} pass.Reportf(fn.Pos(), "%s refers to unknown field or method: %s.%s", fnName, ident, mmbr)
} }
} }
if len(elems) == 3 && !isExampleSuffix(elems[2]) { if len(elems) == 3 && !isExampleSuffix(elems[2]) {