From 50fed64dd90ca6a58cfe8fa7c1061aa8666cc76f Mon Sep 17 00:00:00 2001 From: Keegan Carruthers-Smith Date: Fri, 4 Nov 2016 09:31:35 +0200 Subject: [PATCH] go/doc: don't panic if method is missing recv type Fixes #17788 Change-Id: I2f8a11321dc8f10bebbc8df90ba00ec65b9ee0fa Reviewed-on: https://go-review.googlesource.com/32790 Reviewed-by: Russ Cox --- src/go/doc/reader.go | 5 +++++ src/go/doc/testdata/issue17788.0.golden | 8 ++++++++ src/go/doc/testdata/issue17788.1.golden | 8 ++++++++ src/go/doc/testdata/issue17788.2.golden | 8 ++++++++ src/go/doc/testdata/issue17788.go | 8 ++++++++ 5 files changed, 37 insertions(+) create mode 100644 src/go/doc/testdata/issue17788.0.golden create mode 100644 src/go/doc/testdata/issue17788.1.golden create mode 100644 src/go/doc/testdata/issue17788.2.golden create mode 100644 src/go/doc/testdata/issue17788.go diff --git a/src/go/doc/reader.go b/src/go/doc/reader.go index ca46a047d6a..8e823538689 100644 --- a/src/go/doc/reader.go +++ b/src/go/doc/reader.go @@ -362,6 +362,11 @@ func (r *reader) readFunc(fun *ast.FuncDecl) { // associate methods with the receiver type, if any if fun.Recv != nil { // method + if len(fun.Recv.List) == 0 { + // should not happen (incorrect AST); (See issue 17788) + // don't show this method + return + } recvTypeName, imp := baseTypeName(fun.Recv.List[0].Type) if imp { // should not happen (incorrect AST); diff --git a/src/go/doc/testdata/issue17788.0.golden b/src/go/doc/testdata/issue17788.0.golden new file mode 100644 index 00000000000..42c00da5041 --- /dev/null +++ b/src/go/doc/testdata/issue17788.0.golden @@ -0,0 +1,8 @@ +// +PACKAGE issue17788 + +IMPORTPATH + testdata/issue17788 + +FILENAMES + testdata/issue17788.go diff --git a/src/go/doc/testdata/issue17788.1.golden b/src/go/doc/testdata/issue17788.1.golden new file mode 100644 index 00000000000..42c00da5041 --- /dev/null +++ b/src/go/doc/testdata/issue17788.1.golden @@ -0,0 +1,8 @@ +// +PACKAGE issue17788 + +IMPORTPATH + testdata/issue17788 + +FILENAMES + testdata/issue17788.go diff --git a/src/go/doc/testdata/issue17788.2.golden b/src/go/doc/testdata/issue17788.2.golden new file mode 100644 index 00000000000..42c00da5041 --- /dev/null +++ b/src/go/doc/testdata/issue17788.2.golden @@ -0,0 +1,8 @@ +// +PACKAGE issue17788 + +IMPORTPATH + testdata/issue17788 + +FILENAMES + testdata/issue17788.go diff --git a/src/go/doc/testdata/issue17788.go b/src/go/doc/testdata/issue17788.go new file mode 100644 index 00000000000..883ad5f7695 --- /dev/null +++ b/src/go/doc/testdata/issue17788.go @@ -0,0 +1,8 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue17788 + +func ( /* receiver type */ ) f0() { +}