go/doc: exclude examples with results
Fixes #36185
diff --git a/src/go/doc/example.go b/src/go/doc/example.go
index ba1f863..8c01bf0 100644
--- a/src/go/doc/example.go
+++ b/src/go/doc/example.go
@@ -74,6 +74,9 @@
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
}
diff --git a/src/go/doc/example_test.go b/src/go/doc/example_test.go
index 2fd54f8..db2b2d3 100644
--- a/src/go/doc/example_test.go
+++ b/src/go/doc/example_test.go
@@ -228,6 +228,8 @@
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
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if results := f.Type.Results; results != nil && len(results.List) != 0 {
continue // function has results; not a valid example
}I think that we should allow examples that return an error. If you are interested in implementing that in a follow up commit, then please have a look at the tracking bug https://github.com/golang/go/issues/21111.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if results := f.Type.Results; results != nil && len(results.List) != 0 {
continue // function has results; not a valid example
}I think that we should allow examples that return an error. If you are interested in implementing that in a follow up commit, then please have a look at the tracking bug https://github.com/golang/go/issues/21111.
Until there's an accepted proposal, this is still the right fix.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if results := f.Type.Results; results != nil && len(results.List) != 0 {
continue // function has results; not a valid example
}Sean LiaoI think that we should allow examples that return an error. If you are interested in implementing that in a follow up commit, then please have a look at the tracking bug https://github.com/golang/go/issues/21111.
Until there's an accepted proposal, this is still the right fix.
I fully agree.
That said I wish someone would remove the obsolete `Proposal-Hold` label from bug 21111 so that that proposal can continue.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
if results := f.Type.Results; results != nil && len(results.List) != 0 {
continue // function has results; not a valid example
}Sean LiaoI think that we should allow examples that return an error. If you are interested in implementing that in a follow up commit, then please have a look at the tracking bug https://github.com/golang/go/issues/21111.
Michael SchallerUntil there's an accepted proposal, this is still the right fix.
I fully agree.
That said I wish someone would remove the obsolete `Proposal-Hold` label from bug 21111 so that that proposal can continue.
I've removed the hold and added the proposal to the review agenda.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |