"cmd/internal/src"
)
-// Temporary import helper to get type2-based type-checking going.
type gcimports struct {
+ check *types2.Checker
packages map[string]*types2.Package
}
panic("mode must be 0")
}
- _, pkg, err := readImportFile(path, typecheck.Target, m.packages)
+ _, pkg, err := readImportFile(path, typecheck.Target, m.check, m.packages)
return pkg, err
}
return nil
}
- pkg, _, err := readImportFile(path, typecheck.Target, nil)
+ pkg, _, err := readImportFile(path, typecheck.Target, nil, nil)
if err != nil {
base.Errorf("%s", err)
return nil
// readImportFile reads the import file for the given package path and
// returns its types.Pkg representation. If packages is non-nil, the
// types2.Package representation is also returned.
-func readImportFile(path string, target *ir.Package, packages map[string]*types2.Package) (pkg1 *types.Pkg, pkg2 *types2.Package, err error) {
+func readImportFile(path string, target *ir.Package, check *types2.Checker, packages map[string]*types2.Package) (pkg1 *types.Pkg, pkg2 *types2.Package, err error) {
path, err = resolveImportPath(path)
if err != nil {
return
// checkFiles configures and runs the types2 checker on the given
// parsed source files and then returns the result.
-func checkFiles(noders []*noder, importer types2.Importer) (posMap, *types2.Package, *types2.Info) {
+func checkFiles(noders []*noder) (posMap, *types2.Package, *types2.Info) {
if base.SyntaxErrors() != 0 {
base.ErrorExit()
}
}
// typechecking
+ importer := gcimports{
+ packages: make(map[string]*types2.Package),
+ }
conf := types2.Config{
GoVersion: base.Flag.Lang,
IgnoreLabels: true, // parser already checked via syntax.CheckBranches mode
terr := err.(types2.Error)
base.ErrorfAt(m.makeXPos(terr.Pos), "%s", terr.Msg)
},
- Importer: importer,
+ Importer: &importer,
Sizes: &gcSizes{},
}
info := &types2.Info{
// expand as needed
}
- pkg, err := conf.Check(base.Ctxt.Pkgpath, files, info)
+ pkg := types2.NewPackage(base.Ctxt.Pkgpath, "")
+ importer.check = types2.NewChecker(&conf, pkg, info)
+ err := importer.check.Files(files)
+
base.ExitIfErrors()
if err != nil {
base.FatalfAt(src.NoXPos, "conf.Check error: %v", err)
// check2 type checks a Go package using types2, and then generates IR
// using the results.
func check2(noders []*noder) {
- importer := &gcimports{
- packages: make(map[string]*types2.Package),
- }
-
- m, pkg, info := checkFiles(noders, importer)
+ m, pkg, info := checkFiles(noders)
if base.Flag.G < 2 {
os.Exit(0)