Repository: goplus/gop
Pull request #1270 (2022-06-12 14:24:12)

cl: preloadFile restore cur file
fix mixed .go and .gop
cl preloadFile restore current file.


Patch:
diff --git a/cl/compile.go b/cl/compile.go
index af744958..041d9d41 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -619,7 +619,8 @@ func preloadFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, genCod
 	parent := ctx.pkgCtx
 	syms := parent.syms
 	goFile := getGoFile(file, genCode)
-	p.SetCurFile(goFile, true)
+	old, _ := p.SetCurFile(goFile, true)
+	defer p.RestoreCurFile(old)
 	for _, decl := range f.Decls {
 		switch d := decl.(type) {
 		case *ast.FuncDecl:
@@ -955,13 +956,6 @@ func simplifyGopPackage(pkgPath string) string {
 }
 
 func loadImport(ctx *blockCtx, spec *ast.ImportSpec) {
-	if enableRecover {
-		defer func() {
-			if e := recover(); e != nil {
-				ctx.handleRecover(e)
-			}
-		}()
-	}
 	var pkg *gox.PkgRef
 	var pkgPath = toString(spec.Path)
 	if realPath, kind := checkC2go(pkgPath); kind != c2goInvalid {
diff --git a/go.mod b/go.mod
index fce2611f..bf740931 100644
--- a/go.mod
+++ b/go.mod
@@ -4,8 +4,8 @@ go 1.16
 
 require (
 	github.com/goplus/c2go v0.7.7
-	github.com/goplus/gox v1.11.11-0.20220608064319-a874b7d2ce42
+	github.com/goplus/gox v1.11.10
 	github.com/goplus/libc v0.3.9
-	github.com/goplus/mod v0.9.11
+	github.com/goplus/mod v0.9.10
 	github.com/qiniu/x v1.11.5
 )
diff --git a/go.sum b/go.sum
index 0b88c8d8..e5565225 100644
--- a/go.sum
+++ b/go.sum
@@ -4,14 +4,12 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 github.com/goplus/c2go v0.7.7 h1:/Gw1JmIT8ZxIv9+lQq2XiYKwsseD0mSdhVpWSE3sFpM=
 github.com/goplus/c2go v0.7.7/go.mod h1:PvO1amuwqAPjRs4zIDsrEP+ZC94hl7i6nfUHKXSfRmw=
+github.com/goplus/gox v1.11.10 h1:fayKhbqgrxbD9qylZknDZVvhtSmkMgtxMd0IwXXhTYI=
 github.com/goplus/gox v1.11.10/go.mod h1:gu7fuQF8RmWPZUjd+tEJGuV3m/vOEv0bHrct0x/KatM=
-github.com/goplus/gox v1.11.11-0.20220608064319-a874b7d2ce42 h1:j3B3GhEmewHT/EcaOGFYnsVCifmGF5IZfq1QakUvlHo=
-github.com/goplus/gox v1.11.11-0.20220608064319-a874b7d2ce42/go.mod h1:gu7fuQF8RmWPZUjd+tEJGuV3m/vOEv0bHrct0x/KatM=
 github.com/goplus/libc v0.3.9 h1:1mZngVccEfPlhVa3iVVY7Z0s6Dm4CbO2OiI5x2z46lg=
 github.com/goplus/libc v0.3.9/go.mod h1:ewlp1FCnlqDNJtkjNi7DikLMVfUcLaABJjL4z7QnkNU=
+github.com/goplus/mod v0.9.10 h1:z7wrTT241dPSGJDeMs5uuqv/5CgXLomhOZGWEAZ+OpE=
 github.com/goplus/mod v0.9.10/go.mod h1:NHU13OjeNV3ez1f+R9FLJIlIun0KNSuZb0jnmP3N3o8=
-github.com/goplus/mod v0.9.11 h1:4u/Icor2tH9AbnETTHG0gx4T1Aodi10mCu/+U3V+WCE=
-github.com/goplus/mod v0.9.11/go.mod h1:NHU13OjeNV3ez1f+R9FLJIlIun0KNSuZb0jnmP3N3o8=
 github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
 github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
 github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index 7a3934ed..e6bd411f 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -146,6 +146,25 @@ var c foo
 var d int = c.v
 var e = foo3{}
 var x string = c.Str()
+`)
+	gopMixedClTest(t, "main", `package main
+type Point struct {
+	X int
+	Y int
+}
+`, `
+type T struct{}
+println(&T{},&Point{10,20})
+`, `package main
+
+import fmt "fmt"
+
+type T struct {
+}
+
+func main() {
+	fmt.Println(&T{}, &Point{10, 20})
+}
 `)
 }
 
diff --git a/cl/error_msg_test.go b/cl/error_msg_test.go
index 16385ee9..68c038c4 100644
--- a/cl/error_msg_test.go
+++ b/cl/error_msg_test.go
@@ -17,10 +17,7 @@
 package cl_test
 
 import (
-	"fmt"
 	"os"
-	"path/filepath"
-	"runtime"
 	"testing"
 
 	"github.com/goplus/gop/cl"
@@ -848,21 +845,3 @@ type A struct {
 }
 `)
 }
-
-func TestErrImportPkg(t *testing.T) {
-	codeErrorTest(t,
-		fmt.Sprintf(`./bar.gop:3:2: package fmt2 is not in GOROOT (%v)
-`, filepath.Join(runtime.GOROOT(), "src", "fmt2")), `
-import (
-	"fmt2"
-)
-`)
-
-	codeErrorTest(t, `./bar.gop:3:2: no required module provides package github.com/goplus/gop/fmt2; to add it:
-	go get github.com/goplus/gop/fmt2
-`, `
-import (
-	"github.com/goplus/gop/fmt2"
-)
-`)
-}