[go] go/doc: exclude examples with results

5 views
Skip to first unread message

Sean Liao (Gerrit)

unread,
Dec 14, 2025, 3:05:25 PM (2 days ago) Dec 14
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Sean Liao has uploaded the change for review

Commit message

go/doc: exclude examples with results

Fixes #36185
Change-Id: I7634744e62e00023367ed48a4700b61a6a6a6964

Change diff

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

Change information

Files:
  • M src/go/doc/example.go
  • M src/go/doc/example_test.go
Change size: XS
Delta: 2 files changed, 5 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I7634744e62e00023367ed48a4700b61a6a6a6964
Gerrit-Change-Number: 729902
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Liao <se...@liao.dev>
unsatisfied_requirement
satisfied_requirement
open
diffy

Sean Liao (Gerrit)

unread,
Dec 14, 2025, 3:06:01 PM (2 days ago) Dec 14
to goph...@pubsubhelper.golang.org, Alan Donovan, golang-co...@googlegroups.com
Attention needed from Alan Donovan

Sean Liao voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I7634744e62e00023367ed48a4700b61a6a6a6964
Gerrit-Change-Number: 729902
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Comment-Date: Sun, 14 Dec 2025 20:05:53 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Michael Schaller (Gerrit)

unread,
Dec 15, 2025, 12:37:09 PM (yesterday) Dec 15
to goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Sean Liao

Michael Schaller added 1 comment

File src/go/doc/example.go
Line 77, Patchset 1 (Latest): if results := f.Type.Results; results != nil && len(results.List) != 0 {

continue // function has results; not a valid example
}
Michael Schaller . resolved

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.

Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Sean Liao
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I7634744e62e00023367ed48a4700b61a6a6a6964
    Gerrit-Change-Number: 729902
    Gerrit-PatchSet: 1
    Gerrit-Owner: Sean Liao <se...@liao.dev>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Sean Liao <se...@liao.dev>
    Gerrit-CC: Michael Schaller <mi...@google.com>
    Gerrit-Attention: Sean Liao <se...@liao.dev>
    Gerrit-Attention: Alan Donovan <adon...@google.com>
    Gerrit-Comment-Date: Mon, 15 Dec 2025 17:37:01 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Sean Liao (Gerrit)

    unread,
    Dec 15, 2025, 1:15:38 PM (yesterday) Dec 15
    to goph...@pubsubhelper.golang.org, Michael Schaller, Go LUCI, Alan Donovan, golang-co...@googlegroups.com
    Attention needed from Alan Donovan and Michael Schaller

    Sean Liao added 1 comment

    File src/go/doc/example.go
    Line 77, Patchset 1 (Latest): if results := f.Type.Results; results != nil && len(results.List) != 0 {
    continue // function has results; not a valid example
    }
    Michael Schaller . resolved

    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.

    Sean Liao

    Until there's an accepted proposal, this is still the right fix.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alan Donovan
    • Michael Schaller
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I7634744e62e00023367ed48a4700b61a6a6a6964
    Gerrit-Change-Number: 729902
    Gerrit-PatchSet: 1
    Gerrit-Owner: Sean Liao <se...@liao.dev>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Sean Liao <se...@liao.dev>
    Gerrit-CC: Michael Schaller <mi...@google.com>
    Gerrit-Attention: Alan Donovan <adon...@google.com>
    Gerrit-Attention: Michael Schaller <mi...@google.com>
    Gerrit-Comment-Date: Mon, 15 Dec 2025 18:15:31 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Michael Schaller <mi...@google.com>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Michael Schaller (Gerrit)

    unread,
    3:58 AM (11 hours ago) 3:58 AM
    to goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, golang-co...@googlegroups.com
    Attention needed from Alan Donovan and Sean Liao

    Michael Schaller added 1 comment

    File src/go/doc/example.go
    Line 77, Patchset 1 (Latest): if results := f.Type.Results; results != nil && len(results.List) != 0 {
    continue // function has results; not a valid example
    }
    Michael Schaller . resolved

    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.

    Sean Liao

    Until there's an accepted proposal, this is still the right fix.

    Michael Schaller

    I fully agree.

    That said I wish someone would remove the obsolete `Proposal-Hold` label from bug 21111 so that that proposal can continue.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alan Donovan
    • Sean Liao
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I7634744e62e00023367ed48a4700b61a6a6a6964
    Gerrit-Change-Number: 729902
    Gerrit-PatchSet: 1
    Gerrit-Owner: Sean Liao <se...@liao.dev>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Sean Liao <se...@liao.dev>
    Gerrit-CC: Michael Schaller <mi...@google.com>
    Gerrit-Attention: Sean Liao <se...@liao.dev>
    Gerrit-Attention: Alan Donovan <adon...@google.com>
    Gerrit-Comment-Date: Tue, 16 Dec 2025 08:58:09 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Sean Liao <se...@liao.dev>
    Comment-In-Reply-To: Michael Schaller <mi...@google.com>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Alan Donovan (Gerrit)

    unread,
    1:38 PM (1 hour ago) 1:38 PM
    to goph...@pubsubhelper.golang.org, Michael Schaller, Go LUCI, golang-co...@googlegroups.com
    Attention needed from Sean Liao

    Alan Donovan voted and added 1 comment

    Votes added by Alan Donovan

    Code-Review+2

    1 comment

    File src/go/doc/example.go
    Line 77, Patchset 1 (Latest): if results := f.Type.Results; results != nil && len(results.List) != 0 {
    continue // function has results; not a valid example
    }
    Michael Schaller . resolved

    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.

    Sean Liao

    Until there's an accepted proposal, this is still the right fix.

    Michael Schaller

    I fully agree.

    That said I wish someone would remove the obsolete `Proposal-Hold` label from bug 21111 so that that proposal can continue.

    Alan Donovan

    I've removed the hold and added the proposal to the review agenda.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Sean Liao
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I7634744e62e00023367ed48a4700b61a6a6a6964
    Gerrit-Change-Number: 729902
    Gerrit-PatchSet: 1
    Gerrit-Owner: Sean Liao <se...@liao.dev>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Sean Liao <se...@liao.dev>
    Gerrit-CC: Michael Schaller <mi...@google.com>
    Gerrit-Attention: Sean Liao <se...@liao.dev>
    Gerrit-Comment-Date: Tue, 16 Dec 2025 18:38:44 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages