Repository: goplus/gop
Pull request #1526 (2023-11-07 15:53:52)

jsonrpc2: log handleAsync


Patch:
diff --git a/cl/classfile.go b/cl/classfile.go
index 7c6b5f1c..250fe833 100644
--- a/cl/classfile.go
+++ b/cl/classfile.go
@@ -139,17 +139,18 @@ func getStringConst(spx *gox.PkgRef, name string) string {
 	return ""
 }
 
-func getFields(f *ast.File) []ast.Spec {
+func getFields(f *ast.File) (specs []ast.Spec) {
 	for _, decl := range f.Decls {
 		if g, ok := decl.(*ast.GenDecl); ok {
 			if g.Tok == token.VAR {
-				return g.Specs
+				specs, g.Specs = g.Specs, nil
+				return
 			}
 			continue
 		}
 		break
 	}
-	return nil
+	return
 }
 
 func setBodyHandler(ctx *blockCtx) {
diff --git a/cl/compile.go b/cl/compile.go
index 25a34f27..67d4da0f 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -758,34 +758,21 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con
 						tags = append(tags, "")
 					}
 				}
-				rec := ctx.recorder()
 				for _, v := range specs {
 					spec := v.(*ast.ValueSpec)
+					var embed bool
+					if spec.Names == nil {
+						embed = true
+						v := parseTypeEmbedName(spec.Type)
+						spec.Names = []*ast.Ident{v}
+					}
 					typ := toType(ctx, spec.Type)
-					tag := toFieldTag(spec.Tag)
-					if len(spec.Names) == 0 {
-						name := parseTypeEmbedName(spec.Type)
-						if chk.chkRedecl(ctx, name.Name, spec.Type.Pos()) {
+					for _, name := range spec.Names {
+						if chk.chkRedecl(ctx, name.Name, name.Pos()) {
 							continue
 						}
-						fld := types.NewField(spec.Type.Pos(), pkg, name.Name, typ, true)
-						if rec != nil {
-							rec.Def(name, fld)
-						}
-						flds = append(flds, fld)
-						tags = append(tags, tag)
-					} else {
-						for _, name := range spec.Names {
-							if chk.chkRedecl(ctx, name.Name, name.Pos()) {
-								continue
-							}
-							fld := types.NewField(name.Pos(), pkg, name.Name, typ, false)
-							if rec != nil {
-								rec.Def(name, fld)
-							}
-							flds = append(flds, fld)
-							tags = append(tags, tag)
-						}
+						flds = append(flds, types.NewField(name.Pos(), pkg, name.Name, typ, embed))
+						tags = append(tags, toFieldTag(spec.Tag))
 					}
 				}
 				decl.InitType(p, types.NewStruct(flds, tags))
@@ -847,10 +834,6 @@ func preloadFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, gopFil
 	goFile := genGoFile(file, gopFile)
 	old, _ := p.SetCurFile(goFile, true)
 	defer p.RestoreCurFile(old)
-	var skipClassFields bool
-	if f.IsClass {
-		skipClassFields = true
-	}
 	for _, decl := range f.Decls {
 		switch d := decl.(type) {
 		case *ast.FuncDecl:
@@ -987,10 +970,6 @@ func preloadFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, gopFil
 					})
 				}
 			case token.VAR:
-				if skipClassFields {
-					skipClassFields = false
-					continue
-				}
 				for _, spec := range d.Specs {
 					vSpec := spec.(*ast.ValueSpec)
 					if debugLoad {
diff --git a/x/jsonrpc2/conn.go b/x/jsonrpc2/conn.go
index 0561b8ca..4bd04e75 100644
--- a/x/jsonrpc2/conn.go
+++ b/x/jsonrpc2/conn.go
@@ -691,6 +691,10 @@ func (c *Connection) handleAsync() {
 			continue
 		}
 
+		if debugCall {
+			req := req.Request
+			log.Println("==> handleAsync", req.ID, req.Method, string(req.Params))
+		}
 		result, err := c.handler.Handle(req.ctx, req.Request)
 		c.processResult(c.handler, req, result, err)
 	}
diff --git a/x/typesutil/check.go b/x/typesutil/check.go
index ae5947fd..92ee7ddd 100644
--- a/x/typesutil/check.go
+++ b/x/typesutil/check.go
@@ -164,6 +164,7 @@ func (p *Checker) Files(goFiles []*goast.File, gopFiles []*ast.File) (err error)
 			log.Println("typesutil.Check err:", err)
 			log.SingleStack()
 		}
+		return
 	}
 	if len(files) > 0 {
 		scope := pkgTypes.Scope()


Test patch:
diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go
index 9d387a78..28e0fd71 100644
--- a/cl/compile_spx_test.go
+++ b/cl/compile_spx_test.go
@@ -303,15 +303,15 @@ func onCloned() {
 
 import "github.com/goplus/gop/cl/internal/spx"
 
+type Game struct {
+	*spx.MyGame
+	Kai Kai
+}
 type Kai struct {
 	spx.Sprite
 	*Game
 	a int
 }
-type Game struct {
-	*spx.MyGame
-	Kai Kai
-}
 
 func (this *Game) onInit() {
 	spx.Gopt_Sprite_Clone__0(this.Kai)
@@ -345,11 +345,6 @@ import (
 	"github.com/goplus/gop/cl/internal/spx"
 )
 
-type Kai struct {
-	spx.Sprite
-	*index
-}
-
 var x float64 = spx.Rand__1(1.2)
 
 type index struct {
@@ -357,6 +352,10 @@ type index struct {
 	Kai Kai
 	t   spx.Sound
 }
+type Kai struct {
+	spx.Sprite
+	*index
+}
 
 func (this *index) MainEntry() {
 	spx.Gopt_MyGame_Run(this, "hzip://open.qiniu.us/weather/res.zip")
@@ -494,14 +493,14 @@ var (
 
 import "github.com/goplus/gop/cl/internal/spx2"
 
-type Kai struct {
-	spx2.Sprite
-	*Game
-}
 type Game struct {
 	spx2.Game
 	Kai Kai
 }
+type Kai struct {
+	spx2.Sprite
+	*Game
+}
 
 func (this *Game) MainEntry() {
 }
@@ -530,14 +529,14 @@ import (
 	"github.com/goplus/gop/cl/internal/spx2"
 )
 
-type Kai struct {
-	spx2.Sprite
-	*Game
-}
 type Game struct {
 	spx2.Game
 	Kai Kai
 }
+type Kai struct {
+	spx2.Sprite
+	*Game
+}
 
 func (this *Game) MainEntry() {
 	fmt.Println("Hi")
@@ -631,15 +630,15 @@ type info struct {
 	x int
 	y int
 }
+type Game struct {
+	*spx.MyGame
+	Kai Kai
+}
 type Kai struct {
 	spx.Sprite
 	*Game
 	a int
 }
-type Game struct {
-	*spx.MyGame
-	Kai Kai
-}
 
 func (this *Game) onInit() {
 	spx.Gopt_Sprite_Clone__0(this.Kai)