-
Notifications
You must be signed in to change notification settings - Fork 18k
go/doc: Examples panics on a file containing a function without a body #42706
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
I looked into this a bit. parser.ParseFile and friends do not generate an error for the function with no body but the compiler does. This results in tools like |
A function with no body is valid Go. It is expected to be provided by assembler code or C code or via I haven't looked at this and I'm not sure where it is going wrong, but it would not be correct to modify the parser to reject functions with no bodies. |
Forgive me if this is not constructive. When I try to run an application with a function with no body I get a compilation error. Go Playground Example. This is why I assumed it was not valid. Does that imply an error in the compiler? |
Function bodies may only be omitted in packages that contain assembler code or use cgo or use go:linkname. |
This change guards a call to ast.Inspect with a nil check on the first argument. This avoids a panic when inspecting a reference to a function with an external body. Fixes golang#42706
Change https://golang.org/cl/275516 mentions this issue: |
This change guards a call to ast.Inspect with a nil check on the first argument. This avoids a panic when inspecting a reference to a function with an external body. Fixes golang#42706
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Wrote this example:
Ran
go test
What did you expect to see?
go test
succeed or error with helpful message.What did you see instead?
A panic:
NOTE: The func foo has no body. When I add the body like
func foo(int) {}
it does not panic.The text was updated successfully, but these errors were encountered: