go/doc: avoid panic on reference to external function

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 #42706
This commit is contained in:
Norman B. Lancaster 2020-12-01 12:58:59 -06:00 committed by Daniel Martí
parent d76060814e
commit 08072b9ce5
1 changed files with 4 additions and 1 deletions

View File

@ -237,7 +237,10 @@ func playExample(file *ast.File, f *ast.FuncDecl) *ast.File {
}
}
ast.Inspect(d.Body, inspectFunc)
// Functions might not have a body. See #42706.
if d.Body != nil {
ast.Inspect(d.Body, inspectFunc)
}
case *ast.GenDecl:
for _, spec := range d.Specs {
switch s := spec.(type) {