Skip to content

Commit 65ef999

Browse files
agnivaderobpike
authored andcommitted
cmd/doc: stop showing interface methods while matching symbols
Fixes #31961 Change-Id: I9db9ecfd2f8ca7cf51df4413a6e0d66de5da7043 Reviewed-on: https://go-review.googlesource.com/c/go/+/178457 Run-TryBot: Agniva De Sarker <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rob Pike <[email protected]>
1 parent e2970a4 commit 65ef999

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/cmd/doc/doc_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,19 @@ var tests = []test{
602602
`Comment about exported interface`,
603603
},
604604
},
605+
// Interface method at package level.
606+
{
607+
"interface method at package level",
608+
[]string{p, `ExportedMethod`},
609+
[]string{
610+
`func \(ExportedType\) ExportedMethod\(a int\) bool`,
611+
`Comment about exported method`,
612+
},
613+
[]string{
614+
`Comment before exported method.*\n.*ExportedMethod\(\)` +
615+
`.*Comment on line with exported method`,
616+
},
617+
},
605618

606619
// Method.
607620
{

src/cmd/doc/pkg.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,8 @@ func trimUnexportedFields(fields *ast.FieldList, isInterface bool) *ast.FieldLis
914914
}
915915

916916
// printMethodDoc prints the docs for matches of symbol.method.
917-
// If symbol is empty, it prints all methods that match the name.
918-
// It reports whether it found any methods.
917+
// If symbol is empty, it prints all methods for any concrete type
918+
// that match the name. It reports whether it found any methods.
919919
func (pkg *Package) printMethodDoc(symbol, method string) bool {
920920
defer pkg.flush()
921921
types := pkg.findTypes(symbol)
@@ -937,6 +937,9 @@ func (pkg *Package) printMethodDoc(symbol, method string) bool {
937937
}
938938
continue
939939
}
940+
if symbol == "" {
941+
continue
942+
}
940943
// Type may be an interface. The go/doc package does not attach
941944
// an interface's methods to the doc.Type. We need to dig around.
942945
spec := pkg.findTypeSpec(typ.Decl, typ.Name)

0 commit comments

Comments
 (0)