From 6d0b9575f1b682d155435640a137a3f541ddef82 Mon Sep 17 00:00:00 2001 From: xhd2015 Date: Sun, 7 Apr 2024 00:08:12 +0800 Subject: [PATCH] fix test for go1.17 --- cmd/xgo/version.go | 6 +++--- patch/ctxt/skip_pkg_go1.19_and_below.go | 2 +- patch/syntax/call_expr_go1.17_18_19.go | 16 ++++++++++++++++ patch/syntax/call_expr_go1.20.go | 10 ++++++++++ patch/syntax/vars.go | 12 +----------- runtime/core/version.go | 6 +++--- runtime/functab/functab.go | 2 +- runtime/mock/patch.go | 2 +- support/goinfo/mod.go | 2 +- 9 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 patch/syntax/call_expr_go1.17_18_19.go create mode 100644 patch/syntax/call_expr_go1.20.go diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index 59dae190..78d9f0f6 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -2,9 +2,9 @@ package main import "fmt" -const VERSION = "1.0.18" -const REVISION = "86b60236af7fe7147b90073421f57187fbf6990a+1" -const NUMBER = 165 +const VERSION = "1.0.19" +const REVISION = "7b94c97a1b438510f46aa86fca2b626396b9d2e1+1" +const NUMBER = 166 func getRevision() string { revSuffix := "" diff --git a/patch/ctxt/skip_pkg_go1.19_and_below.go b/patch/ctxt/skip_pkg_go1.19_and_below.go index 745122dd..9c9b14d8 100644 --- a/patch/ctxt/skip_pkg_go1.19_and_below.go +++ b/patch/ctxt/skip_pkg_go1.19_and_below.go @@ -1,7 +1,7 @@ //go:build go1.17 && !go1.20 // +build go1.17,!go1.20 -package ctx +package ctxt import ( "strings" diff --git a/patch/syntax/call_expr_go1.17_18_19.go b/patch/syntax/call_expr_go1.17_18_19.go new file mode 100644 index 00000000..1744f4ca --- /dev/null +++ b/patch/syntax/call_expr_go1.17_18_19.go @@ -0,0 +1,16 @@ +//go:build !go1.20 +// +build !go1.20 + +package syntax + +import "cmd/compile/internal/syntax" + +func (ctx *BlockContext) traverseCallExpr(node *syntax.CallExpr, globaleNames map[string]*DeclInfo, imports map[string]string) *syntax.CallExpr { + if node == nil { + return nil + } + for i, arg := range node.ArgList { + node.ArgList[i] = ctx.traverseExpr(arg, globaleNames, imports) + } + return node +} diff --git a/patch/syntax/call_expr_go1.20.go b/patch/syntax/call_expr_go1.20.go new file mode 100644 index 00000000..aba8968e --- /dev/null +++ b/patch/syntax/call_expr_go1.20.go @@ -0,0 +1,10 @@ +//go:build go1.20 +// +build go1.20 + +package syntax + +import "cmd/compile/internal/syntax" + +func (ctx *BlockContext) traverseCallExpr(node syntax.Expr, globaleNames map[string]*DeclInfo, imports map[string]string) syntax.Expr { + return ctx.traverseExpr(node, globaleNames, imports) +} diff --git a/patch/syntax/vars.go b/patch/syntax/vars.go index af2cd7de..91fb94fd 100644 --- a/patch/syntax/vars.go +++ b/patch/syntax/vars.go @@ -46,16 +46,6 @@ func collectVarDecls(declKind DeclKind, names []*syntax.Name, typ syntax.Expr) [ return decls } -type vis struct { -} - -var _ syntax.Visitor = (*vis)(nil) - -// Visit implements syntax.Visitor. -func (c *vis) Visit(node syntax.Node) (w syntax.Visitor) { - return nil -} - func trapVariables(pkgPath string, fileList []*syntax.File, funcDelcs []*DeclInfo) { names := make(map[string]*DeclInfo, len(funcDelcs)) varNames := make(map[string]bool) @@ -198,7 +188,7 @@ func (ctx *BlockContext) traverseStmt(node syntax.Stmt, globaleNames map[string] return ctx.traverseBlockStmt(node, globaleNames, imports) case *syntax.CallStmt: // defer, go - node.Call = ctx.traverseExpr(node.Call, globaleNames, imports) + node.Call = ctx.traverseCallExpr(node.Call, globaleNames, imports) return node case *syntax.IfStmt: node.Init = ctx.traverseSimpleStmt(node.Init, globaleNames, imports) diff --git a/runtime/core/version.go b/runtime/core/version.go index c588e223..2bfd1403 100644 --- a/runtime/core/version.go +++ b/runtime/core/version.go @@ -6,9 +6,9 @@ import ( "os" ) -const VERSION = "1.0.18" -const REVISION = "86b60236af7fe7147b90073421f57187fbf6990a+1" -const NUMBER = 165 +const VERSION = "1.0.19" +const REVISION = "7b94c97a1b438510f46aa86fca2b626396b9d2e1+1" +const NUMBER = 166 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/runtime/functab/functab.go b/runtime/functab/functab.go index 70cec131..c57126d8 100644 --- a/runtime/functab/functab.go +++ b/runtime/functab/functab.go @@ -60,7 +60,7 @@ func InfoFunc(fn interface{}) *core.FuncInfo { func InfoVar(addr interface{}) *core.FuncInfo { ensureMapping() v := reflect.ValueOf(addr) - if v.Kind() != reflect.Pointer { + if v.Kind() != reflect.Ptr { panic(fmt.Errorf("given type is not a pointer: %T", addr)) } ptr := v.Pointer() diff --git a/runtime/mock/patch.go b/runtime/mock/patch.go index 0ef829f7..1a376f78 100644 --- a/runtime/mock/patch.go +++ b/runtime/mock/patch.go @@ -28,7 +28,7 @@ func Patch(fn interface{}, replacer interface{}) func() { if fnType != reflect.TypeOf(replacer) { panic(fmt.Errorf("replacer should have type: %T, actual: %T", fn, replacer)) } - } else if fnKind == reflect.Pointer { + } else if fnKind == reflect.Ptr { replacerType := reflect.TypeOf(replacer) wantType := reflect.FuncOf(nil, []reflect.Type{fnType.Elem()}, false) var targetTypeStr string diff --git a/support/goinfo/mod.go b/support/goinfo/mod.go index 4af1cd7a..9bd67660 100644 --- a/support/goinfo/mod.go +++ b/support/goinfo/mod.go @@ -29,7 +29,7 @@ func ResolveMainModule(dir string, args []string) (string, error) { return modPath, nil - // // has quailified name: not starting with ./ or ../ + // // has qualified name: not starting with ./ or ../ // var qualifieldNames []string // for _, arg := range args { // if !isRelative(arg) {