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

go.tools/go/types: minor cleanups

R=adonovan
CC=golang-dev
https://golang.org/cl/26430045
This commit is contained in:
Robert Griesemer 2013-11-14 21:38:04 -08:00
parent 19dd02b670
commit 91e5190eb9
3 changed files with 28 additions and 29 deletions

View File

@ -131,7 +131,7 @@ func Import(imports map[string]*types.Package, path string) (pkg *types.Package,
filename, id := FindPkg(path, srcDir)
if filename == "" {
err = errors.New("can't find import: " + id)
err = fmt.Errorf("can't find import: %s", id)
return
}
@ -893,6 +893,7 @@ func (p *parser) parseFuncDecl() {
// Decl = [ ImportDecl | ConstDecl | TypeDecl | VarDecl | FuncDecl | MethodDecl ] "\n" .
//
func (p *parser) parseDecl() {
if p.tok == scanner.Ident {
switch p.lit {
case "import":
p.parseImportDecl()
@ -910,6 +911,7 @@ func (p *parser) parseDecl() {
p.parseFuncDecl()
}
}
}
p.expect('\n')
}
@ -922,11 +924,9 @@ func (p *parser) parseDecl() {
func (p *parser) parseExport() *types.Package {
p.expectKeyword("package")
name := p.parsePackageName()
if p.tok != '\n' {
// A package is safe if it was compiled with the -u flag,
// which disables the unsafe package.
// TODO(gri) remember "safe" package
p.expectKeyword("safe")
if p.tok == scanner.Ident && p.lit == "safe" {
// package was compiled with -u option - ignore
p.next()
}
p.expect('\n')

View File

@ -26,18 +26,17 @@ func pkgFor(path, source string, info *Info) (*Package, error) {
}
var conf Config
pkg, err := conf.Check(f.Name.Name, fset, []*ast.File{f}, info)
if err != nil {
return nil, err
}
return pkg, nil
return conf.Check(f.Name.Name, fset, []*ast.File{f}, info)
}
func mustTypecheck(t *testing.T, path, source string, info *Info) string {
pkg, err := pkgFor(path, source, info)
if err != nil {
t.Fatalf("%s: didn't type-check (%s)", path, err)
name := path
if pkg != nil {
name = "package " + pkg.Name()
}
t.Fatalf("%s: didn't type-check (%s)", name, err)
}
return pkg.Name()
}
@ -259,7 +258,6 @@ func TestInitOrder(t *testing.T) {
{`package p9; type T struct{}; func (T) m() int { _ = y; return 0 }; var x, y = T.m, 1`, []string{
"y = 1", "x = T.m",
}},
// TODO(gri) add more tests
}
for _, test := range tests {

View File

@ -377,6 +377,7 @@ func (check *checker) resolveFiles(files []*ast.File) {
}
}
}
seenPkgs = nil // not needed anymore
// Phase 2: Verify that objects in package and file scopes have different names.