Skip to content
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

go/doc: panic in go/doc.lastComment when parsing an Example_foo with no body #29271

Closed
bcmills opened this issue Dec 14, 2018 · 6 comments
Closed
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Dec 14, 2018

@alandonovan found this panic in #28044: https://play.golang.org/p/Gs4iMjqFmgu

With this input program:

package p
func Example() {}
func Example_a()

doc.Examples panics with this stack trace:

go/ast.(*BlockStmt).Pos(...)
	/usr/local/go/src/go/ast/ast.go:728
go/doc.lastComment(0x0, 0x0, 0x0, 0x0, 0x15d060, 0x92a)
	/usr/local/go/src/go/doc/example.go:409 +0x6
go/doc.exampleOutput(0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x40e238, 0x0)
	/usr/local/go/src/go/doc/example.go:108 +0x40
go/doc.Examples(0x42bf90, 0x1, 0x1, 0x197480, 0x1e9cb8, 0x0, 0x437580, 0x0)
	/usr/local/go/src/go/doc/example.go:75 +0x320

CC @griesemer

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 14, 2018
@bcmills bcmills added this to the Go1.13 milestone Dec 14, 2018
@griesemer griesemer self-assigned this Dec 14, 2018
@griesemer
Copy link
Contributor

Probably missing a nil check somewhere when there' no function body (*ast.BlockStmt is nil).

@rcodeb
Copy link

rcodeb commented Dec 15, 2018

Sorry to barge in, I believe, https://github.com/golang/go/blob/master/src/go/doc/example.go#L389 here there should be a check for the nil body.

@agnivade
Copy link
Contributor

Will take a look.

@agnivade agnivade assigned agnivade and unassigned griesemer Dec 16, 2018
@gopherbot
Copy link

Change https://golang.org/cl/154380 mentions this issue: go/doc: handle Examples with no body

@rcodeb
Copy link

rcodeb commented Dec 16, 2018

@agnivade may be return from the function where I pointed in my comment as returning nil will be ok for pointer to file return type.

@agnivade
Copy link
Contributor

Please comment on the CL as it will be easier to review there.

@golang golang locked and limited conversation to collaborators Dec 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants