-
Notifications
You must be signed in to change notification settings - Fork 18k
go/doc: whole file is used as example even when there are tests or benchmarks #38409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for finding the bug! |
@gopherbot please open a backport issue for 1.14. This is a regression that impacts user visible documentations, without a workaround on the doc generation side (as opposed to modifying the target source, which might be an existing version or third-party). |
Backport issue(s) opened: #38418 (for 1.14). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
Fixed by CL 222477 (PR #37730), thank you @flyingmutant. /cc @griesemer @agnivade |
Change https://golang.org/cl/232868 mentions this issue: |
After CL 211357 (commit 499dc1c), hasTests and numDecl were not updated properly for function declarations with parameters, which affected the whole file example detection logic. This caused examples like package foo_test func Foo(x int) { } func Example() { fmt.Println("Hello, world!") // Output: Hello, world! } to not be detected as whole file ones. Fixes #38418. For #38409. Change-Id: I9ebd47e52d7ee9d91eb6f8e0257511de69b2a402 GitHub-Last-Rev: cc71c31 GitHub-Pull-Request: #37730 Reviewed-on: https://go-review.googlesource.com/c/go/+/222477 Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com> Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> (cherry picked from commit c4961dc) Reviewed-on: https://go-review.googlesource.com/c/go/+/232868 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Gregory Petrosyan <gregory.petrosyan@gmail.com>
Change https://golang.org/cl/239180 mentions this issue: |
This CL uses the fix from CL 222477 (golang/go#38409), to fix detection of whole file examples. Fixes golang/go#39006 Fixes golang/go#39727 Change-Id: Iaf9240f7637a1723e681cdbb0d06bf36a43d8d2a Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/239180 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Package
testing
says:This program produces expected results in Go 1.13:
It stopped working in Go 1.14:
This is because CL 211357 added an early
continue
when the function being considered has parameters. The intention was to skip Example functions with parameters. However, the skip happens too early, before this check:Tests and benchmarks always have 1 parameter, so
hasTests
never has a chance to get set to true./cc @jayconrod @matloob
The text was updated successfully, but these errors were encountered: