Merge pull request #11 from thought-machine/use-golang15-builtins

Update imports to use builtin versions of packages from 1.5.
This commit is contained in:
Francesc Campoy 2016-04-19 12:14:23 -07:00
commit 5bfdb73f88

View File

@ -16,9 +16,9 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"golang.org/x/tools/go/exact" "go/constant"
_ "golang.org/x/tools/go/gcimporter" "go/importer"
"golang.org/x/tools/go/types" "go/types"
) )
// A Package contains all the information related to a parsed package. // A Package contains all the information related to a parsed package.
@ -59,7 +59,7 @@ func ParsePackage(directory, skipPrefix, skipSuffix string) (*Package, error) {
// type-check the package // type-check the package
defs := make(map[*ast.Ident]types.Object) defs := make(map[*ast.Ident]types.Object)
config := types.Config{FakeImportC: true} config := types.Config{FakeImportC: true, Importer: importer.Default()}
info := &types.Info{Defs: defs} info := &types.Info{Defs: defs}
if _, err := config.Check(directory, fs, files, info); err != nil { if _, err := config.Check(directory, fs, files, info); err != nil {
return nil, fmt.Errorf("type-checking package: %v", err) return nil, fmt.Errorf("type-checking package: %v", err)
@ -150,7 +150,7 @@ func (pkg *Package) valuesOfTypeIn(typeName string, decl *ast.GenDecl) ([]string
return nil, fmt.Errorf("can't handle non-integer constant type %s", typ) return nil, fmt.Errorf("can't handle non-integer constant type %s", typ)
} }
value := obj.(*types.Const).Val() // Guaranteed to succeed as this is CONST. value := obj.(*types.Const).Val() // Guaranteed to succeed as this is CONST.
if value.Kind() != exact.Int { if value.Kind() != constant.Int {
log.Fatalf("can't happen: constant is not an integer %s", name) log.Fatalf("can't happen: constant is not an integer %s", name)
} }
values = append(values, name.Name) values = append(values, name.Name)