go/doc: exclude examples with results

Fixes #36185

Change-Id: I7634744e62e00023367ed48a4700b61a6a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/729902
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Sean Liao 2025-12-14 20:02:33 +00:00
parent 5046bdf8a6
commit ea1aa76554
2 changed files with 5 additions and 0 deletions

View File

@ -74,6 +74,9 @@ func Examples(testFiles ...*ast.File) []*Example {
if params := f.Type.Params; len(params.List) != 0 {
continue // function has params; not a valid example
}
if results := f.Type.Results; results != nil && len(results.List) != 0 {
continue // function has results; not a valid example
}
if f.Body == nil { // ast.File.Body nil dereference (see issue 28044)
continue
}

View File

@ -228,6 +228,8 @@ func ExampleFunc1_foo() {}
func ExampleFunc1_foo_suffix() {}
func ExampleFunc1_foo_Suffix() {} // matches Func1, instead of Func1_foo
func Examplefunc1() {} // invalid - cannot match unexported
func ExampleFunc1_params(a int) {} // invalid - has parameter
func ExampleFunc1_results() int {} // invalid - has results
func ExampleType1_Func1() {}
func ExampleType1_Func1_() {} // invalid - suffix must start with a lower-case letter