Skip to content

Commit 6aabc1c

Browse files
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 <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e250d35 commit 6aabc1c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

go/analysis/passes/tests/testdata/src/b_x_test/b_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package b_x_test
22

3-
import "b"
3+
import (
4+
"a"
5+
"b"
6+
)
47

58
func ExampleFoo_F() {
69
var x b.Foo
710
x.F()
11+
a.Foo()
812
}
913

1014
func ExampleFoo_G() { // want "ExampleFoo_G refers to unknown field or method: Foo.G"

go/analysis/passes/tests/tests.go

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

0 commit comments

Comments
 (0)