diff --git a/go/types/api.go b/go/types/api.go index 6eb10340..0f9277b0 100644 --- a/go/types/api.go +++ b/go/types/api.go @@ -23,6 +23,7 @@ package types import ( + "bytes" "fmt" "go/ast" "go/token" @@ -189,6 +190,19 @@ type Initializer struct { Rhs ast.Expr } +func (init *Initializer) String() string { + var buf bytes.Buffer + for i, lhs := range init.Lhs { + if i > 0 { + buf.WriteString(", ") + } + buf.WriteString(lhs.Name()) + } + buf.WriteString(" = ") + WriteExpr(&buf, init.Rhs) + return buf.String() +} + // Check type-checks a package and returns the resulting package object, // the first error if any, and if info != nil, additional type information. // The package is marked as complete if no errors occurred, otherwise it is diff --git a/go/types/api_test.go b/go/types/api_test.go index 9abbfdb0..eca697e9 100644 --- a/go/types/api_test.go +++ b/go/types/api_test.go @@ -7,7 +7,6 @@ package types_test import ( - "bytes" "go/ast" "go/parser" "go/token" @@ -19,7 +18,7 @@ import ( ) func pkgFor(path, source string, info *Info) (*Package, error) { - fset = token.NewFileSet() + fset := token.NewFileSet() f, err := parser.ParseFile(fset, path, source, 0) if err != nil { return nil, err @@ -210,19 +209,6 @@ func TestScopesInfo(t *testing.T) { } } -func initString(init *Initializer) string { - var buf bytes.Buffer - for i, lhs := range init.Lhs { - if i > 0 { - buf.WriteString(", ") - } - buf.WriteString(lhs.Name()) - } - buf.WriteString(" = ") - WriteExpr(&buf, init.Rhs) - return buf.String() -} - func TestInitOrder(t *testing.T) { var tests = []struct { src string @@ -272,7 +258,7 @@ func TestInitOrder(t *testing.T) { // initializers must match for i, want := range test.inits { - got := initString(info.InitOrder[i]) + got := info.InitOrder[i].String() if got != want { t.Errorf("package %s, init %d: got %s; want %s", name, i, got, want) continue diff --git a/go/types/resolver.go b/go/types/resolver.go index 28195c35..66d69f70 100644 --- a/go/types/resolver.go +++ b/go/types/resolver.go @@ -147,7 +147,7 @@ func (check *checker) resolveFiles(files []*ast.File) { importer := check.conf.Import if importer == nil { if DefaultImport == nil { - panic("no Config.Import and no DefaultImport") + panic(`no Config.Import or DefaultImport (missing import _ "code.google.com/p/go.tools/go/gcimporter"?)`) } importer = DefaultImport }