diff --git a/cl/compile.go b/cl/compile.go index 466d3fcee..58fee873f 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -31,6 +31,7 @@ import ( "github.com/goplus/gop/ast/fromgo" "github.com/goplus/gop/token" "github.com/goplus/gox" + "github.com/goplus/gox/packages" "github.com/goplus/mod/modfile" ) @@ -372,12 +373,17 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package, if targetDir == "" { targetDir = workingDir } + fset := conf.Fset + imp := conf.Importer + if imp == nil { + imp = packages.NewImporter(fset, workingDir) + } files := pkg.Files - interp := &nodeInterp{fset: conf.Fset, files: files, workingDir: workingDir} + interp := &nodeInterp{fset: fset, files: files, workingDir: workingDir} ctx := &pkgCtx{syms: make(map[string]loader), nodeInterp: interp} confGox := &gox.Config{ - Fset: conf.Fset, - Importer: newGopImporter(conf.GopRoot, conf.Importer), + Fset: fset, + Importer: newGopImporter(conf.GopRoot, imp), LoadNamed: ctx.loadNamed, HandleErr: ctx.handleErr, NodeInterpreter: interp, diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go index 24ffa55d5..534350339 100644 --- a/cl/compile_spx_test.go +++ b/cl/compile_spx_test.go @@ -403,6 +403,7 @@ func (this *Kai) onMsg(msg string) { func TestSpxMainEntry(t *testing.T) { conf := *gblConf + conf.Importer = nil conf.NoAutoGenMain = false gopSpxTestExConf(t, "Nocode", &conf, ` diff --git a/load.go b/load.go index 3e695dde6..93bc61fd7 100644 --- a/load.go +++ b/load.go @@ -29,7 +29,6 @@ import ( "github.com/goplus/gop/parser" "github.com/goplus/gop/x/gopenv" "github.com/goplus/gox" - "github.com/goplus/gox/packages" "github.com/goplus/mod/env" "github.com/goplus/mod/gopmod" ) @@ -58,10 +57,6 @@ func LoadDir(dir string, conf *Config) (out, test *gox.Package, err error) { if gop == nil { gop = gopenv.Get() } - imp := conf.Importer - if imp == nil { - imp = packages.NewImporter(fset, dir) - } mod, err := gopmod.Load(dir, gop) if err != nil && err != syscall.ENOENT { @@ -96,7 +91,7 @@ func LoadDir(dir string, conf *Config) (out, test *gox.Package, err error) { WorkingDir: dir, GopRoot: gop.Root, Fset: fset, - Importer: imp, + Importer: conf.Importer, LookupClass: mod.LookupClass, } for name, pkg := range pkgs {