From 08072b9ce5c1fd4ee77eba6f1acc0a84e838ad7b Mon Sep 17 00:00:00 2001 From: "Norman B. Lancaster" Date: Tue, 1 Dec 2020 12:58:59 -0600 Subject: [PATCH] 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 --- src/go/doc/example.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/go/doc/example.go b/src/go/doc/example.go index 125fd530b1..274000cecb 100644 --- a/src/go/doc/example.go +++ b/src/go/doc/example.go @@ -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) {