Repository: goplus/gop
Pull request #1268 (2022-06-10 13:33:17)

cl: loadImport check recover


Patch:
diff --git a/cl/compile.go b/cl/compile.go
index 2822621e..af744958 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -955,6 +955,13 @@ 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 bf740931..fce2611f 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.10
+	github.com/goplus/gox v1.11.11-0.20220608064319-a874b7d2ce42
 	github.com/goplus/libc v0.3.9
-	github.com/goplus/mod v0.9.10
+	github.com/goplus/mod v0.9.11
 	github.com/qiniu/x v1.11.5
 )
diff --git a/go.sum b/go.sum
index e5565225..0b88c8d8 100644
--- a/go.sum
+++ b/go.sum
@@ -4,12 +4,14 @@ 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/error_msg_test.go b/cl/error_msg_test.go
index 68c038c4..16385ee9 100644
--- a/cl/error_msg_test.go
+++ b/cl/error_msg_test.go
@@ -17,7 +17,10 @@
 package cl_test
 
 import (
+	"fmt"
 	"os"
+	"path/filepath"
+	"runtime"
 	"testing"
 
 	"github.com/goplus/gop/cl"
@@ -845,3 +848,21 @@ 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"
+)
+`)
+}