Repository: goplus/gop
Pull request #1497 (2023-10-28 06:11:29)

goxRecorder.Member: rec.Type


Patch:
diff --git a/cl/compile.go b/cl/compile.go
index 250ff0e2..9f0123f9 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -222,15 +222,18 @@ type goxRecorder struct {
 
 // Member maps identifiers to the objects they denote.
 func (p *goxRecorder) Member(id ast.Node, obj types.Object) {
+	tv := types.TypeAndValue{Type: obj.Type()}
 	switch v := id.(type) {
 	case *ast.SelectorExpr:
 		sel := v.Sel
 		// TODO: record event for a Go ident
 		if _, ok := fromgo.CheckIdent(sel); !ok {
 			p.rec.Use(sel, obj)
+			p.rec.Type(v, tv)
 		}
-	case *ast.Ident: // it's impossible converted from Go
+	case *ast.Ident: // it's in a classfile and impossible converted from Go
 		p.rec.Use(v, obj)
+		p.rec.Type(v, tv)
 	}
 }
 
@@ -1040,7 +1043,7 @@ func loadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool) {
 		}
 	}
 	sig := toFuncType(ctx, d.Type, recv, d)
-	fn, err := ctx.pkg.NewFuncWith(d.Name.Pos(), name, sig, func() token.Pos {
+	fn, err := ctx.pkg.NewFuncWith(d.Pos(), name, sig, func() token.Pos {
 		return d.Recv.List[0].Type.Pos()
 	})
 	if err != nil {
diff --git a/cl/func_type_and_var.go b/cl/func_type_and_var.go
index a9f6e12b..9a734d47 100644
--- a/cl/func_type_and_var.go
+++ b/cl/func_type_and_var.go
@@ -319,12 +319,7 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
 			if t, ok := typ.(*types.Named); ok { // #1196: embedded type should ensure loaded
 				ctx.loadNamed(ctx.pkg, t)
 			}
-			fld := types.NewField(field.Type.Pos(), pkg, name, typ, true)
-			if rec := ctx.recorder(); rec != nil {
-				if ident := parseTypeEmbedName(field.Type); ident != nil {
-					rec.Def(ident, fld)
-				}
-			}
+			fld := types.NewField(token.NoPos, pkg, name, typ, true)
 			fields = append(fields, fld)
 			tags = append(tags, toFieldTag(field.Tag))
 			continue
@@ -333,10 +328,7 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
 			if chk.chkRedecl(ctx, name.Name, name.NamePos) {
 				continue
 			}
-			fld := types.NewField(name.Pos(), pkg, name.Name, typ, false)
-			if rec := ctx.recorder(); rec != nil {
-				rec.Def(name, fld)
-			}
+			fld := types.NewField(token.NoPos, pkg, name.Name, typ, false)
 			fields = append(fields, fld)
 			tags = append(tags, toFieldTag(field.Tag))
 		}
diff --git a/cl/outline/cl/compile.go b/cl/outline/cl/compile.go
index 51423513..fe5e3634 100644
--- a/cl/outline/cl/compile.go
+++ b/cl/outline/cl/compile.go
@@ -750,7 +750,7 @@ func preloadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool)
 		}
 	}
 	sig := toFuncType(ctx, d.Type, recv, d)
-	fn, err := ctx.pkg.NewFuncWith(d.Name.Pos(), name, sig, func() token.Pos {
+	fn, err := ctx.pkg.NewFuncWith(d.Pos(), name, sig, func() token.Pos {
 		return d.Recv.List[0].Type.Pos()
 	})
 	if err != nil {
diff --git a/cl/outline/cl/func_type_and_var.go b/cl/outline/cl/func_type_and_var.go
index 9a412d49..cb52ef9d 100644
--- a/cl/outline/cl/func_type_and_var.go
+++ b/cl/outline/cl/func_type_and_var.go
@@ -285,7 +285,7 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
 			if chk.chkRedecl(ctx, name, field.Type.Pos()) {
 				continue
 			}
-			fld := types.NewField(field.Type.Pos(), pkg, name, typ, true)
+			fld := types.NewField(token.NoPos, pkg, name, typ, true)
 			fields = append(fields, fld)
 			tags = append(tags, toFieldTag(field.Tag))
 			continue
@@ -294,7 +294,7 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
 			if chk.chkRedecl(ctx, name.Name, name.NamePos) {
 				continue
 			}
-			fld := types.NewField(name.Pos(), pkg, name.Name, typ, false)
+			fld := types.NewField(token.NoPos, pkg, name.Name, typ, false)
 			fields = append(fields, fld)
 			tags = append(tags, toFieldTag(field.Tag))
 		}
diff --git a/go.mod b/go.mod
index c860cb1b..9f5c3012 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.18
 require (
 	github.com/fsnotify/fsnotify v1.7.0
 	github.com/goplus/c2go v0.7.16
-	github.com/goplus/gox v1.12.2-0.20231026084726-48d24f42e91f
+	github.com/goplus/gox v1.12.2-0.20231024165412-08fb2524d4a0
 	github.com/goplus/mod v0.11.8-0.20231019172744-da5848421263
 	github.com/qiniu/x v1.13.1
 	golang.org/x/tools v0.14.0
diff --git a/go.sum b/go.sum
index 51af496d..f4e77783 100644
--- a/go.sum
+++ b/go.sum
@@ -7,8 +7,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
 github.com/goplus/c2go v0.7.16 h1:B9jRNNytoq7yDBQOZSm2qENQhRQMfNhgOea5XHWNUnI=
 github.com/goplus/c2go v0.7.16/go.mod h1:XODEFX2PeEEJXNLLdykWeZgMSaKJ51fVm+C9IM3FxNQ=
 github.com/goplus/gox v1.12.1/go.mod h1:wymoQJ7ydd42cTlaXb4wNbvn4LlKjR+j8PZehI7v1zQ=
-github.com/goplus/gox v1.12.2-0.20231026084726-48d24f42e91f h1:WGAwExBl2dwEopwlAdnnfbTRiStvTUasONduDWxirlU=
-github.com/goplus/gox v1.12.2-0.20231026084726-48d24f42e91f/go.mod h1:Ek1YIy3wRaZ1i0DD2XG29i3r5AFdhcOradK0/GGs1YQ=
+github.com/goplus/gox v1.12.2-0.20231024165412-08fb2524d4a0 h1:60n144rwLnIapa5Vs9LIhh6QeaKrI26eWh0eJLVL4eM=
+github.com/goplus/gox v1.12.2-0.20231024165412-08fb2524d4a0/go.mod h1:Ek1YIy3wRaZ1i0DD2XG29i3r5AFdhcOradK0/GGs1YQ=
 github.com/goplus/mod v0.11.5/go.mod h1:NDC5E+XOT8vcJCMjqKhLDJHTHX7lyVN4Vbfi2U7dBhs=
 github.com/goplus/mod v0.11.8-0.20231019172744-da5848421263 h1:PE0HveOss5mai9pa52L4/ZvVqZtltogJ9rIUIsdlG/I=
 github.com/goplus/mod v0.11.8-0.20231019172744-da5848421263/go.mod h1:yl2QncBKTdXk+8UaNsdo4u2zSpGEJYA5JKjgD3K2h00=


Test patch:
diff --git a/cl/error_msg_test.go b/cl/error_msg_test.go
index 6ac17953..7bd7d1b1 100644
--- a/cl/error_msg_test.go
+++ b/cl/error_msg_test.go
@@ -431,7 +431,7 @@ for _, a = range b {
 
 func TestErrInitFunc(t *testing.T) {
 	codeErrorTest(t,
-		`./bar.gop:2:6: func init must have no arguments and no return values`, `
+		`./bar.gop:2:1: func init must have no arguments and no return values`, `
 func init(v byte) {
 }
 `)
diff --git a/cl/outline/cl/error_msg_test.go b/cl/outline/cl/error_msg_test.go
index 29919464..a07c414c 100644
--- a/cl/outline/cl/error_msg_test.go
+++ b/cl/outline/cl/error_msg_test.go
@@ -431,7 +431,7 @@ for _, a = range b {
 
 func TestErrInitFunc(t *testing.T) {
 	codeErrorTest(t,
-		`./bar.gop:2:6: func init must have no arguments and no return values`, `
+		`./bar.gop:2:1: func init must have no arguments and no return values`, `
 func init(v byte) {
 }
 `)
diff --git a/cl/typeparams_test.go b/cl/typeparams_test.go
index a3b71457..c700ce1d 100644
--- a/cl/typeparams_test.go
+++ b/cl/typeparams_test.go
@@ -591,38 +591,3 @@ func test(v1 int, v2 *Data) {
 }
 `)
 }
-
-func TestGenericTypeCompositeLit(t *testing.T) {
-	gopMixedClTest(t, "main", `package main
-type A[T any] struct {
-	m T
-}
-
-type B[T any] struct {
-	n A[T]
-}
-
-`, `
-var a [2]int
-if 0 == a[1] {
-	println "world"
-}
-println B[int]{}.n
-if 0 < (B[int]{}).n.m {
-}
-`, `package main
-
-import "fmt"
-
-var a [2]int
-
-func main() {
-	if 0 == a[1] {
-		fmt.Println("world")
-	}
-	fmt.Println(B[int]{}.n)
-	if 0 < (B[int]{}).n.m {
-	}
-}
-`)
-}