diff --git a/go/gcimporter/gcimporter.go b/go/gcimporter/gcimporter.go index 86aba4fc..439269c2 100644 --- a/go/gcimporter/gcimporter.go +++ b/go/gcimporter/gcimporter.go @@ -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,21 +893,23 @@ func (p *parser) parseFuncDecl() { // Decl = [ ImportDecl | ConstDecl | TypeDecl | VarDecl | FuncDecl | MethodDecl ] "\n" . // func (p *parser) parseDecl() { - switch p.lit { - case "import": - p.parseImportDecl() - case "const": - p.parseConstDecl() - case "type": - p.parseTypeDecl() - case "var": - p.parseVarDecl() - case "func": - p.next() // look ahead - if p.tok == '(' { - p.parseMethodDecl() - } else { - p.parseFuncDecl() + if p.tok == scanner.Ident { + switch p.lit { + case "import": + p.parseImportDecl() + case "const": + p.parseConstDecl() + case "type": + p.parseTypeDecl() + case "var": + p.parseVarDecl() + case "func": + p.next() // look ahead + if p.tok == '(' { + p.parseMethodDecl() + } else { + 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') diff --git a/go/types/api_test.go b/go/types/api_test.go index f7fb33e6..598f121c 100644 --- a/go/types/api_test.go +++ b/go/types/api_test.go @@ -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 { diff --git a/go/types/resolver.go b/go/types/resolver.go index daddb8b1..28195c35 100644 --- a/go/types/resolver.go +++ b/go/types/resolver.go @@ -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.