Repository: goplus/gop
Pull request #1744 (2024-02-14 12:50:37)

cl: fix callCmdNoArgs skip types record


Patch:
diff --git a/cl/classfile.go b/cl/classfile.go
index 3ebf85e7..725811e0 100644
--- a/cl/classfile.go
+++ b/cl/classfile.go
@@ -267,9 +267,6 @@ func gmxMainFunc(pkg *gox.Package, ctx *pkgCtx, noAutoGenMain bool) func() {
 				new := pkg.Builtin().Ref("new")
 				cb := fn.BodyStart(pkg).Val(new).Val(o).Call(1).MemberVal("Main")
 
-				// force remove //line comments for main func
-				cb.SetComments(nil, false)
-
 				sig := cb.Get(-1).Type.(*types.Signature)
 				narg := gmxMainNarg(sig)
 				if narg > 0 {
diff --git a/cl/compile.go b/cl/compile.go
index 9f05b1e2..d3b2336f 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -368,10 +368,9 @@ type blockCtx struct {
 	classRecv  *ast.FieldList // available when gmxSettings != nil
 	fileScope  *types.Scope   // only valid when isGopFile
 	rec        *typesRecorder
-
-	fileLine  bool
-	isClass   bool
-	isGopFile bool // is Go+ file or not
+	fileLine   bool
+	isClass    bool
+	isGopFile  bool // is Go+ file or not
 }
 
 func (bc *blockCtx) recorder() *typesRecorder {
diff --git a/cl/expr.go b/cl/expr.go
index 9854dd53..7c007366 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -297,6 +297,7 @@ func compileExpr(ctx *blockCtx, expr ast.Expr, inFlags ...int) {
 		compileSelectorExpr(ctx, v, flags)
 		if cmdNoArgs {
 			callCmdNoArgs(ctx, expr, true)
+			return
 		}
 	case *ast.BinaryExpr:
 		compileBinaryExpr(ctx, v)
diff --git a/cl/stmt.go b/cl/stmt.go
index 954ca189..8c76e460 100644
--- a/cl/stmt.go
+++ b/cl/stmt.go
@@ -47,21 +47,17 @@ func relFile(dir string, absFile string) string {
 
 func commentStmt(ctx *blockCtx, stmt ast.Stmt) {
 	if ctx.fileLine {
-		commentStmtEx(ctx.cb, ctx.pkgCtx, stmt)
-	}
-}
-
-func commentStmtEx(cb *gox.CodeBuilder, ctx *pkgCtx, stmt ast.Stmt) {
-	start := stmt.Pos()
-	pos := ctx.fset.Position(start)
-	if ctx.relBaseDir != "" {
-		pos.Filename = fileLineFile(ctx.relBaseDir, pos.Filename)
-	}
-	line := fmt.Sprintf("\n//line %s:%d:1", pos.Filename, pos.Line)
-	comments := &goast.CommentGroup{
-		List: []*goast.Comment{{Text: line}},
+		start := stmt.Pos()
+		pos := ctx.fset.Position(start)
+		if ctx.relBaseDir != "" {
+			pos.Filename = fileLineFile(ctx.relBaseDir, pos.Filename)
+		}
+		line := fmt.Sprintf("\n//line %s:%d:1", pos.Filename, pos.Line)
+		comments := &goast.CommentGroup{
+			List: []*goast.Comment{{Text: line}},
+		}
+		ctx.cb.SetComments(comments, false)
 	}
-	cb.SetComments(comments, false)
 }
 
 func commentFunc(ctx *blockCtx, fn *gox.Func, decl *ast.FuncDecl) {


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index c75e737a..6cd295c3 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -122,18 +122,6 @@ func gopClTestFS(t *testing.T, conf *cl.Config, fs parser.FileSystem, pkgname, e
 	}
 }
 
-func TestTypeDoc(t *testing.T) {
-	gopClTest(t, `
-type (
-	// doc
-	A int
-)
-`, `package main
-// doc
-type A int
-`)
-}
-
 func TestUnsafe(t *testing.T) {
 	gopClTest(t, `
 import "unsafe"
diff --git a/x/typesutil/info_test.go b/x/typesutil/info_test.go
index df54147f..14a31fb0 100644
--- a/x/typesutil/info_test.go
+++ b/x/typesutil/info_test.go
@@ -1387,7 +1387,7 @@ func OnKey__a(a, b string, v ...int) {
 031: 33: 3 | onKey               | func (*main.N).OnKey__8(x int, y int)`)
 }
 
-func _TestMixedOverload3(t *testing.T) { // TODO:
+func TestMixedOverload3(t *testing.T) {
 	testGopInfo(t, `
 Test
 Test 100