1
0
mirror of https://github.com/golang/go synced 2024-11-19 01:14:39 -07:00

go.tools/go/types: String method for Initializers

Plus a couple of minor fixes.

R=adonovan
CC=golang-dev
https://golang.org/cl/28540043
This commit is contained in:
Robert Griesemer 2013-11-18 11:26:49 -08:00
parent a284a61701
commit 65aa1a4fbe
3 changed files with 17 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}