go.tools/go/types: minor cleanups
R=adonovan CC=golang-dev https://golang.org/cl/26430045
This commit is contained in:
parent
19dd02b670
commit
91e5190eb9
|
|
@ -131,7 +131,7 @@ func Import(imports map[string]*types.Package, path string) (pkg *types.Package,
|
||||||
|
|
||||||
filename, id := FindPkg(path, srcDir)
|
filename, id := FindPkg(path, srcDir)
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
err = errors.New("can't find import: " + id)
|
err = fmt.Errorf("can't find import: %s", id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -893,21 +893,23 @@ func (p *parser) parseFuncDecl() {
|
||||||
// Decl = [ ImportDecl | ConstDecl | TypeDecl | VarDecl | FuncDecl | MethodDecl ] "\n" .
|
// Decl = [ ImportDecl | ConstDecl | TypeDecl | VarDecl | FuncDecl | MethodDecl ] "\n" .
|
||||||
//
|
//
|
||||||
func (p *parser) parseDecl() {
|
func (p *parser) parseDecl() {
|
||||||
switch p.lit {
|
if p.tok == scanner.Ident {
|
||||||
case "import":
|
switch p.lit {
|
||||||
p.parseImportDecl()
|
case "import":
|
||||||
case "const":
|
p.parseImportDecl()
|
||||||
p.parseConstDecl()
|
case "const":
|
||||||
case "type":
|
p.parseConstDecl()
|
||||||
p.parseTypeDecl()
|
case "type":
|
||||||
case "var":
|
p.parseTypeDecl()
|
||||||
p.parseVarDecl()
|
case "var":
|
||||||
case "func":
|
p.parseVarDecl()
|
||||||
p.next() // look ahead
|
case "func":
|
||||||
if p.tok == '(' {
|
p.next() // look ahead
|
||||||
p.parseMethodDecl()
|
if p.tok == '(' {
|
||||||
} else {
|
p.parseMethodDecl()
|
||||||
p.parseFuncDecl()
|
} else {
|
||||||
|
p.parseFuncDecl()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.expect('\n')
|
p.expect('\n')
|
||||||
|
|
@ -922,11 +924,9 @@ func (p *parser) parseDecl() {
|
||||||
func (p *parser) parseExport() *types.Package {
|
func (p *parser) parseExport() *types.Package {
|
||||||
p.expectKeyword("package")
|
p.expectKeyword("package")
|
||||||
name := p.parsePackageName()
|
name := p.parsePackageName()
|
||||||
if p.tok != '\n' {
|
if p.tok == scanner.Ident && p.lit == "safe" {
|
||||||
// A package is safe if it was compiled with the -u flag,
|
// package was compiled with -u option - ignore
|
||||||
// which disables the unsafe package.
|
p.next()
|
||||||
// TODO(gri) remember "safe" package
|
|
||||||
p.expectKeyword("safe")
|
|
||||||
}
|
}
|
||||||
p.expect('\n')
|
p.expect('\n')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,18 +26,17 @@ func pkgFor(path, source string, info *Info) (*Package, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var conf Config
|
var conf Config
|
||||||
pkg, err := conf.Check(f.Name.Name, fset, []*ast.File{f}, info)
|
return conf.Check(f.Name.Name, fset, []*ast.File{f}, info)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return pkg, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustTypecheck(t *testing.T, path, source string, info *Info) string {
|
func mustTypecheck(t *testing.T, path, source string, info *Info) string {
|
||||||
pkg, err := pkgFor(path, source, info)
|
pkg, err := pkgFor(path, source, info)
|
||||||
if err != nil {
|
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()
|
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{
|
{`package p9; type T struct{}; func (T) m() int { _ = y; return 0 }; var x, y = T.m, 1`, []string{
|
||||||
"y = 1", "x = T.m",
|
"y = 1", "x = T.m",
|
||||||
}},
|
}},
|
||||||
// TODO(gri) add more tests
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// Phase 2: Verify that objects in package and file scopes have different names.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue