]> Cypherpunks repositories - gostls13.git/commitdiff
go/doc: fix build
authorRobert Griesemer <gri@golang.org>
Wed, 22 May 2013 21:22:50 +0000 (14:22 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 22 May 2013 21:22:50 +0000 (14:22 -0700)
1) go/doc:
   - create correct ast.FuncType
   - use more commonly used variable names in a test case

2) make ast.FuncType.Pos robust in case of incorrect ASTs

R=golang-dev
CC=golang-dev
https://golang.org/cl/9651044

src/pkg/go/ast/ast.go
src/pkg/go/doc/example.go
src/pkg/go/doc/example_test.go

index e8599184a67fb46bda432828f57b56c68580a665..f26ff6b1af3ae3e940775d5b8801eab6efa0ceed 100644 (file)
@@ -439,7 +439,7 @@ func (x *KeyValueExpr) Pos() token.Pos   { return x.Key.Pos() }
 func (x *ArrayType) Pos() token.Pos      { return x.Lbrack }
 func (x *StructType) Pos() token.Pos     { return x.Struct }
 func (x *FuncType) Pos() token.Pos {
-       if x.Func.IsValid() {
+       if x.Func.IsValid() || x.Params == nil { // see issue 3870
                return x.Func
        }
        return x.Params.Pos() // interface method declarations have no "func" keyword
index 2761083c7eed99c6828bfc19b4ee74808183b8da..2358ed38902f36f9f4758f27b788a6bc08e6eeda 100644 (file)
@@ -265,7 +265,7 @@ func playExample(file *ast.File, body *ast.BlockStmt) *ast.File {
        // Synthesize main function.
        funcDecl := &ast.FuncDecl{
                Name: ast.NewIdent("main"),
-               Type: &ast.FuncType{},
+               Type: &ast.FuncType{Params: &ast.FieldList{}}, // FuncType.Params must be non-nil
                Body: body,
        }
 
index e0477e3f6930b81d529e770b1304ae3b1391de5d..e154ea8bfc5be8a79d16b6e3d99269b36978e37e 100644 (file)
@@ -159,8 +159,8 @@ func main() {
 `
 
 func TestExamples(t *testing.T) {
-       fs := token.NewFileSet()
-       file, err := parser.ParseFile(fs, "test.go", strings.NewReader(exampleTestFile), parser.ParseComments)
+       fset := token.NewFileSet()
+       file, err := parser.ParseFile(fset, "test.go", strings.NewReader(exampleTestFile), parser.ParseComments)
        if err != nil {
                t.Fatal(err)
        }
@@ -174,11 +174,11 @@ func TestExamples(t *testing.T) {
                        if e.Play == nil {
                                g = "<nil>"
                        } else {
-                               b := new(bytes.Buffer)
-                               if err := format.Node(b, fs, e.Play); err != nil {
+                               var buf bytes.Buffer
+                               if err := format.Node(&buf, fset, e.Play); err != nil {
                                        t.Fatal(err)
                                }
-                               g = b.String()
+                               g = buf.String()
                        }
                        if g != w {
                                t.Errorf("%s: got Play == %q, want %q", c.Name, g, w)