Repository: goplus/gop
Pull request #1141 (2022-04-16 03:15:45)

gox v1.10.3


Patch:
diff --git a/go.mod b/go.mod
index 90a7df82..97a028c2 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/goplus/gop
 go 1.16
 
 require (
-	github.com/goplus/gox v1.9.15
+	github.com/goplus/gox v1.10.3
 	github.com/qiniu/x v1.11.5
 	golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
 	golang.org/x/tools v0.1.10
diff --git a/go.sum b/go.sum
index 62476315..7dced5d7 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,5 @@
-github.com/goplus/gox v1.9.15 h1:a9X8sJtq9BDiH24FxRuoW7nePohz9OPApQGlkg4QRrY=
-github.com/goplus/gox v1.9.15/go.mod h1:gu7fuQF8RmWPZUjd+tEJGuV3m/vOEv0bHrct0x/KatM=
+github.com/goplus/gox v1.10.3 h1:21//48zPOBstWOhiG9tzufJ0CiHkroRPLj2EzfanIFM=
+github.com/goplus/gox v1.10.3/go.mod h1:gu7fuQF8RmWPZUjd+tEJGuV3m/vOEv0bHrct0x/KatM=
 github.com/qiniu/x v1.11.5 h1:TYr5cl4g2yoHAZeDK4MTjKF6CMoG+IHlCDvvM5qym6U=
 github.com/qiniu/x v1.11.5/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs=
 github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
diff --git a/x/gengo/gengo.go b/x/gengo/gengo.go
index 446968cc..def17b5a 100644
--- a/x/gengo/gengo.go
+++ b/x/gengo/gengo.go
@@ -186,27 +186,13 @@ func (p *Runner) genGoPkgs(conf *Config) {
 		p.state = stateDone
 		return
 	}
-	imps := getKeys(imports)
 	modRoot := p.modRoot
-	impConf := &packages.Config{
-		ModRoot: modRoot,
-		ModPath: p.modPath,
-		Loaded:  conf.Loaded,
-		Fset:    conf.Fset,
-	}
 	inModCache := modfetch.InModCachePath(modRoot)
 	if inModCache {
 		os.Chmod(modRoot, 0755)
 		defer os.Chmod(modRoot, 0555)
 	}
-	imp, _, err := packages.NewImporter(impConf, imps...)
-	if err != nil {
-		conf.OnErr("newImporter", err)
-		p.state = stateOccurErrors
-		return
-	}
-	defer imp.Close()
-	conf.OnInfo("newImporter: %v\n", imps)
+	imp := packages.NewImporter(conf.Fset)
 	for _, pkg := range p.pkgs {
 		if pkg.flags == pkgFlagChanged {
 			p.genGoPkg(pkg, imp, conf)
diff --git a/x/gopproj/gopfiles.go b/x/gopproj/gopfiles.go
index eb5418ea..dcbccde4 100644
--- a/x/gopproj/gopfiles.go
+++ b/x/gopproj/gopfiles.go
@@ -127,10 +127,7 @@ func (p *gopFiles) GenGo(outFile, modFile string) error {
 			os.Chdir(wd)
 		}()
 	}
-	conf.Importer, _, err = packages.NewImporter(nil, "github.com/goplus/gop/builtin")
-	if err != nil {
-		return err
-	}
+	conf.Importer = packages.NewImporter(fset)
 	out, err := cl.NewPackage("", mainPkg, conf)
 	if err != nil {
 		return err


Test patch:
diff --git a/cl/builtin_test.go b/cl/builtin_test.go
index 1fe44902..1af6b22e 100644
--- a/cl/builtin_test.go
+++ b/cl/builtin_test.go
@@ -33,18 +33,7 @@ var (
 
 func getGoxConf() *gox.Config {
 	fset := token.NewFileSet()
-	conf := &packages.Config{
-		ModPath: "github.com/goplus/gop/cl",
-		Loaded:  make(map[string]*types.Package),
-		Fset:    fset,
-	}
-	const (
-		pkgspx2 = "github.com/goplus/gop/cl/internal/spx2"
-	)
-	imp, _, err := packages.NewImporter(conf, ".", pkgspx2)
-	if err != nil {
-		panic(err)
-	}
+	imp := packages.NewImporter(fset)
 	return &gox.Config{Fset: fset, Importer: imp}
 }
 
diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go
index 001682d9..f0dbfc04 100644
--- a/cl/compile_spx_test.go
+++ b/cl/compile_spx_test.go
@@ -219,7 +219,6 @@ type index struct {
 func (this *index) bar() {
 }
 func (this *index) onInit() {
-	Foo
 	this.bar()
 	fmt.Println("Hi")
 }
diff --git a/cl/compile_test.go b/cl/compile_test.go
index 007b701f..030ae61e 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -18,7 +18,6 @@ package cl_test
 
 import (
 	"bytes"
-	"go/types"
 	"os"
 	"strings"
 	"sync"
@@ -42,23 +41,7 @@ func init() {
 	gox.SetDebug(gox.DbgFlagAll)
 	cl.SetDebug(cl.DbgFlagAll)
 	gblFset = token.NewFileSet()
-	conf := &packages.Config{
-		ModRoot: ".",
-		ModPath: "github.com/goplus/gop/cl",
-		Loaded:  make(map[string]*types.Package),
-		Fset:    gblFset,
-	}
-	const (
-		pkgbi   = "github.com/goplus/gop/builtin"
-		pkggt   = "github.com/goplus/gop/ast/goptest"
-		pkgspx  = "github.com/goplus/gop/cl/internal/spx"
-		pkgspx2 = "github.com/goplus/gop/cl/internal/spx2"
-	)
-	imp, _, err := packages.NewImporter(
-		conf, ".", "encoding/base32", "encoding/base64", pkgbi, pkggt, pkgspx, pkgspx2)
-	if err != nil {
-		panic(err)
-	}
+	imp := packages.NewImporter(gblFset)
 	gblConf = &cl.Config{
 		Fset:          gblFset,
 		Importer:      imp,
@@ -163,14 +146,14 @@ const (
 )
 `, `package main
 
-func main() {
-	const a = append + len
-}
-
 const (
 	append = iota
 	len
 )
+
+func main() {
+	const a = append + len
+}
 `)
 }