]> Cypherpunks repositories - gostls13.git/commitdiff
go/doc: don't panic if method is missing recv type
authorKeegan Carruthers-Smith <keegan.csmith@gmail.com>
Fri, 4 Nov 2016 07:31:35 +0000 (09:31 +0200)
committerRuss Cox <rsc@golang.org>
Fri, 11 Nov 2016 15:59:01 +0000 (15:59 +0000)
Fixes #17788

Change-Id: I2f8a11321dc8f10bebbc8df90ba00ec65b9ee0fa
Reviewed-on: https://go-review.googlesource.com/32790
Reviewed-by: Russ Cox <rsc@golang.org>
src/go/doc/reader.go
src/go/doc/testdata/issue17788.0.golden [new file with mode: 0644]
src/go/doc/testdata/issue17788.1.golden [new file with mode: 0644]
src/go/doc/testdata/issue17788.2.golden [new file with mode: 0644]
src/go/doc/testdata/issue17788.go [new file with mode: 0644]

index ca46a047d6af089346eb3157cbee1481a3ec6512..8e823538689be2fb783d89c4b0898fd86939b002 100644 (file)
@@ -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 (file)
index 0000000..42c00da
--- /dev/null
@@ -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 (file)
index 0000000..42c00da
--- /dev/null
@@ -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 (file)
index 0000000..42c00da
--- /dev/null
@@ -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 (file)
index 0000000..883ad5f
--- /dev/null
@@ -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() {
+}