]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/doc: stop showing interface methods while matching symbols
authorAgniva De Sarker <agnivade@yahoo.co.in>
Wed, 22 May 2019 08:05:04 +0000 (10:05 +0200)
committerRob Pike <r@golang.org>
Thu, 23 May 2019 09:19:03 +0000 (09:19 +0000)
Fixes #31961

Change-Id: I9db9ecfd2f8ca7cf51df4413a6e0d66de5da7043
Reviewed-on: https://go-review.googlesource.com/c/go/+/178457
Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/doc/doc_test.go
src/cmd/doc/pkg.go

index 22468db1ff84ee361049fc375e3bac9464eda5ea..bc870aca5846c8fe6eaf1c105ca26cdffa778a70 100644 (file)
@@ -602,6 +602,19 @@ var tests = []test{
                        `Comment about exported interface`,
                },
        },
+       // Interface method at package level.
+       {
+               "interface method at package level",
+               []string{p, `ExportedMethod`},
+               []string{
+                       `func \(ExportedType\) ExportedMethod\(a int\) bool`,
+                       `Comment about exported method`,
+               },
+               []string{
+                       `Comment before exported method.*\n.*ExportedMethod\(\)` +
+                               `.*Comment on line with exported method`,
+               },
+       },
 
        // Method.
        {
index 12b76c2ad094d9b57e7316eaff5bf1246879b427..32810bd5811d8c962231b50db1bcf2a21d6ea15e 100644 (file)
@@ -914,8 +914,8 @@ func trimUnexportedFields(fields *ast.FieldList, isInterface bool) *ast.FieldLis
 }
 
 // printMethodDoc prints the docs for matches of symbol.method.
-// If symbol is empty, it prints all methods that match the name.
-// It reports whether it found any methods.
+// If symbol is empty, it prints all methods for any concrete type
+// that match the name. It reports whether it found any methods.
 func (pkg *Package) printMethodDoc(symbol, method string) bool {
        defer pkg.flush()
        types := pkg.findTypes(symbol)
@@ -937,6 +937,9 @@ func (pkg *Package) printMethodDoc(symbol, method string) bool {
                        }
                        continue
                }
+               if symbol == "" {
+                       continue
+               }
                // Type may be an interface. The go/doc package does not attach
                // an interface's methods to the doc.Type. We need to dig around.
                spec := pkg.findTypeSpec(typ.Decl, typ.Name)