From dff1b75601820beba61d63db384baee0a1b1b8a8 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 28 Oct 2023 15:15:42 +0800 Subject: [PATCH 1/2] cl.compileIdent: rec.Use for builtin objects --- cl/expr.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cl/expr.go b/cl/expr.go index 632308e29..cd6328ef8 100644 --- a/cl/expr.go +++ b/cl/expr.go @@ -74,7 +74,7 @@ const ( const errorPkgPath = "github.com/qiniu/x/errors" -func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (obj *gox.PkgRef, kind int) { +func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (pkg *gox.PkgRef, kind int) { fvalue := (flags&clIdentSelectorExpr) != 0 || (flags&clIdentLHS) == 0 name := ident.Name if name == "_" { @@ -85,6 +85,7 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (obj *gox.PkgRef, return } + var oldo types.Object scope := ctx.pkg.Types.Scope() at, o := ctx.cb.Scope().LookupParent(name, token.NoPos) if o != nil { @@ -137,7 +138,7 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (obj *gox.PkgRef, if (flags&clIdentAllowBuiltin) == 0 && isBuiltin(o) && !strings.HasPrefix(o.Name(), "print") { panic(ctx.newCodeErrorf(ident.Pos(), "use of builtin %s not in function call", name)) } - o = obj + oldo, o = o, obj } else if o == nil { if (clIdentGoto & flags) != 0 { l := ident.Obj.Data.(*ast.Ident) @@ -153,12 +154,14 @@ find: ctx.cb.VarRef(o, ident) } if rec := ctx.recorder(); rec != nil { - rec.Use(ident, o) e := ctx.cb.Get(-1) - tv := types.TypeAndValue{Type: e.Type, Value: e.CVal} - if !fvalue { - tv.Type = o.Type() + if oldo != nil && gox.IsTypeEx(e.Type) { + rec.Use(ident, oldo) + return } + rec.Use(ident, o) + typ, _ := gox.DerefType(e.Type) + tv := types.TypeAndValue{Type: typ, Value: e.CVal} rec.Type(ident, tv) } return From 519478a08f6c82be0f571dfd07c367ed5a2de4c8 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 28 Oct 2023 15:18:10 +0800 Subject: [PATCH 2/2] gox.IsTypeEx --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9f5c30127..9c910ffe1 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.20231024165412-08fb2524d4a0 + github.com/goplus/gox v1.12.2-0.20231028071646-bb6d796d66cf 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 f4e77783f..2489e2909 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.20231024165412-08fb2524d4a0 h1:60n144rwLnIapa5Vs9LIhh6QeaKrI26eWh0eJLVL4eM= -github.com/goplus/gox v1.12.2-0.20231024165412-08fb2524d4a0/go.mod h1:Ek1YIy3wRaZ1i0DD2XG29i3r5AFdhcOradK0/GGs1YQ= +github.com/goplus/gox v1.12.2-0.20231028071646-bb6d796d66cf h1:67Lz2V9Nj6pZz+u4d9uq5rCfw2t/zE34Qo6AF5dJN3c= +github.com/goplus/gox v1.12.2-0.20231028071646-bb6d796d66cf/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=