]> Cypherpunks repositories - gostls13.git/commitdiff
go/ast: break out after first variable in ExampleCommentMap
authorgo101 <tapir.liu@gmail.com>
Fri, 22 Feb 2019 02:11:55 +0000 (02:11 +0000)
committerRobert Griesemer <gri@golang.org>
Wed, 27 Feb 2019 00:00:14 +0000 (00:00 +0000)
The current ExampleCommentMap might panic if there are more satisfied
comments in the parsed program.

Change-Id: Ibe6943470aa0cfb450dae9fc07c1199acaabef73
GitHub-Last-Rev: c79e98c2868179ea47618b296ce28c5eebc0b99d
GitHub-Pull-Request: golang/go#28587
Reviewed-on: https://go-review.googlesource.com/c/147359
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/ast/example_test.go

index 52a77981b81935532c59c3fb89ca5181a64b4621..e3013f64bed87e3e8ff2e41311688346b5cea41f 100644 (file)
@@ -151,7 +151,7 @@ package main
 const hello = "Hello, World!" // line comment 1
 
 // This comment is associated with the foo variable.
-var foo = hello // line comment 2 
+var foo = hello // line comment 2
 
 // This comment is associated with the main function.
 func main() {
@@ -176,6 +176,7 @@ func main() {
                if gen, ok := decl.(*ast.GenDecl); ok && gen.Tok == token.VAR {
                        copy(f.Decls[i:], f.Decls[i+1:])
                        f.Decls = f.Decls[:len(f.Decls)-1]
+                       break
                }
        }