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
// 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,
}
`
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)
}
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)