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:
parent
e250d351ec
commit
6aabc1ca79
|
@ -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"
|
||||||
|
|
|
@ -153,11 +153,11 @@ 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 {
|
if !found {
|
||||||
pass.Reportf(fn.Pos(), "%s refers to unknown field or method: %s.%s", fnName, ident, mmbr)
|
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]) {
|
||||||
// Check ExampleFoo_Method_suffix and ExampleFoo_Method_Badsuffix.
|
// Check ExampleFoo_Method_suffix and ExampleFoo_Method_Badsuffix.
|
||||||
pass.Reportf(fn.Pos(), "%s has malformed example suffix: %s", fnName, elems[2])
|
pass.Reportf(fn.Pos(), "%s has malformed example suffix: %s", fnName, elems[2])
|
||||||
|
|
Loading…
Reference in New Issue