Commit e3a72b05 authored by Robert Griesemer's avatar Robert Griesemer

go/doc: fix build

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
parent 8f37e419
...@@ -439,7 +439,7 @@ func (x *KeyValueExpr) Pos() token.Pos { return x.Key.Pos() } ...@@ -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 *ArrayType) Pos() token.Pos { return x.Lbrack }
func (x *StructType) Pos() token.Pos { return x.Struct } func (x *StructType) Pos() token.Pos { return x.Struct }
func (x *FuncType) Pos() token.Pos { 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.Func
} }
return x.Params.Pos() // interface method declarations have no "func" keyword return x.Params.Pos() // interface method declarations have no "func" keyword
......
...@@ -265,7 +265,7 @@ func playExample(file *ast.File, body *ast.BlockStmt) *ast.File { ...@@ -265,7 +265,7 @@ func playExample(file *ast.File, body *ast.BlockStmt) *ast.File {
// Synthesize main function. // Synthesize main function.
funcDecl := &ast.FuncDecl{ funcDecl := &ast.FuncDecl{
Name: ast.NewIdent("main"), Name: ast.NewIdent("main"),
Type: &ast.FuncType{}, Type: &ast.FuncType{Params: &ast.FieldList{}}, // FuncType.Params must be non-nil
Body: body, Body: body,
} }
......
...@@ -159,8 +159,8 @@ func main() { ...@@ -159,8 +159,8 @@ func main() {
` `
func TestExamples(t *testing.T) { func TestExamples(t *testing.T) {
fs := token.NewFileSet() fset := token.NewFileSet()
file, err := parser.ParseFile(fs, "test.go", strings.NewReader(exampleTestFile), parser.ParseComments) file, err := parser.ParseFile(fset, "test.go", strings.NewReader(exampleTestFile), parser.ParseComments)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -174,11 +174,11 @@ func TestExamples(t *testing.T) { ...@@ -174,11 +174,11 @@ func TestExamples(t *testing.T) {
if e.Play == nil { if e.Play == nil {
g = "<nil>" g = "<nil>"
} else { } else {
b := new(bytes.Buffer) var buf bytes.Buffer
if err := format.Node(b, fs, e.Play); err != nil { if err := format.Node(&buf, fset, e.Play); err != nil {
t.Fatal(err) t.Fatal(err)
} }
g = b.String() g = buf.String()
} }
if g != w { if g != w {
t.Errorf("%s: got Play == %q, want %q", c.Name, g, w) t.Errorf("%s: got Play == %q, want %q", c.Name, g, w)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment