diff --git a/cmd/xgo/runtime_gen/core/version.go b/cmd/xgo/runtime_gen/core/version.go index a4d3a5e7..2febb1fc 100755 --- a/cmd/xgo/runtime_gen/core/version.go +++ b/cmd/xgo/runtime_gen/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.39" -const REVISION = "55af407f826d020bcd28c51663d0879f8d1ca76e+1" -const NUMBER = 258 +const REVISION = "4d63b2ed7ce161f17d1c311a9b536e82a01769f0+1" +const NUMBER = 259 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index 0e926faf..00bb464a 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -3,8 +3,8 @@ package main import "fmt" const VERSION = "1.0.39" -const REVISION = "55af407f826d020bcd28c51663d0879f8d1ca76e+1" -const NUMBER = 258 +const REVISION = "4d63b2ed7ce161f17d1c311a9b536e82a01769f0+1" +const NUMBER = 259 func getRevision() string { revSuffix := "" diff --git a/patch/info/decl_info.go b/patch/info/decl_info.go index 9eb03525..4cbce152 100644 --- a/patch/info/decl_info.go +++ b/patch/info/decl_info.go @@ -41,8 +41,10 @@ func (c DeclKind) String() string { } type DeclInfo struct { - FuncDecl *syntax.FuncDecl - VarDecl *syntax.VarDecl + FuncDecl *syntax.FuncDecl + VarDecl *syntax.VarDecl + + // when kind == CONST ConstDecl *syntax.ConstDecl // is this var decl follow a const __xgo_trap_xxx = 1? diff --git a/patch/syntax/syntax.go b/patch/syntax/syntax.go index 86c72cb1..22e94017 100644 --- a/patch/syntax/syntax.go +++ b/patch/syntax/syntax.go @@ -773,6 +773,18 @@ func generateFuncRegBody(pos syntax.Pos, funcDecls []*DeclInfo, xgoRegFunc strin // there are function with name "_" continue } + // type unknown constant expr, will not be registered, + // see bug https://github.com/xhd2015/xgo/issues/53 + // why not filter them earlier? + // because the node still needs to be marked, but effectively skipped + if funcDecl.Kind == info.Kind_Const && funcDecl.ConstDecl.Type == nil { + untypedConstType := getConstDeclValueType(funcDecl.ConstDecl.Values) + if untypedConstType == "" || untypedConstType == UNKNOWN_CONST_TYPE { + // exclude + continue + } + } + var fnRefName syntax.Expr var varRefName syntax.Expr if funcDecl.Kind.IsFunc() { diff --git a/runtime/core/version.go b/runtime/core/version.go index a4d3a5e7..2febb1fc 100644 --- a/runtime/core/version.go +++ b/runtime/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.39" -const REVISION = "55af407f826d020bcd28c51663d0879f8d1ca76e+1" -const NUMBER = 258 +const REVISION = "4d63b2ed7ce161f17d1c311a9b536e82a01769f0+1" +const NUMBER = 259 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/runtime/test/debug/debug_test.go b/runtime/test/debug/debug_test.go index cf05eddb..56782591 100644 --- a/runtime/test/debug/debug_test.go +++ b/runtime/test/debug/debug_test.go @@ -12,18 +12,17 @@ import ( "testing" ) +const userNsLength = (1 << 16) const ( - pod1 = "pod1" + minimumMappingUID = userNsLength + mappingLen = userNsLength * 2000 ) -type Pod struct { - Name string -} - -func TestConstNameCollision(t *testing.T) { - var pod1 *Pod +// see bug https://github.com/xhd2015/xgo/issues/176 +func TestUntypedUnknownConstShouldCompile(t *testing.T) { + var allocated uint32 - if pod1 != nil && pod1.Name != "" { - t.Fatalf("pod1 should be empty") + if allocated > minimumMappingUID+mappingLen-userNsLength { + t.Fatalf("allocated is greater?") } } diff --git a/runtime/test/patch_const/patch_const_op_test.go b/runtime/test/patch_const/patch_const_op_test.go index 511850cf..f61c13c2 100644 --- a/runtime/test/patch_const/patch_const_op_test.go +++ b/runtime/test/patch_const/patch_const_op_test.go @@ -1,6 +1,7 @@ package patch_const import ( + "fmt" "testing" "time" @@ -10,9 +11,24 @@ import ( const A = 20 * time.Second func TestPatchConstOp(t *testing.T) { - mock.PatchByName("github.com/xhd2015/xgo/runtime/test/patch_const", "A", func() time.Duration { - return 10 * time.Second - }) + // patch should fail because registering were filtered + var errMsg string + func() { + defer func() { + if e := recover(); e != nil { + errMsg = fmt.Sprint(e) + } + }() + mock.PatchByName("github.com/xhd2015/xgo/runtime/test/patch_const", "A", func() time.Duration { + return 10 * time.Second + }) + }() + + expectErr := "failed to setup mock for: github.com/xhd2015/xgo/runtime/test/patch_const.A" + if errMsg != expectErr { + t.Fatalf("expect errMsg to be: %q, actual: %q", expectErr, errMsg) + } + a := A if a != 20*time.Second { t.Fatalf("expect patch A failed because current xgo does not resolve operation type, actual: a=%v, want: %v", a, 20*time.Second) diff --git a/runtime/test/trap/trap_math_max_test.go b/runtime/test/trap/trap_math_max_test.go new file mode 100644 index 00000000..9e6dd569 --- /dev/null +++ b/runtime/test/trap/trap_math_max_test.go @@ -0,0 +1,22 @@ +package trap + +import ( + "math" + "testing" +) + +// these should compile +// see bug https://github.com/xhd2015/xgo/issues/53 + +const SET_EMPTY_STRING = "" +const SET_ZERO = math.MaxInt64 - 1 +const SET_ZERO_UINT = math.MaxUint64 - 1 +const SET_ZERO_INT32 = math.MaxInt32 - 1 +const SET_ZERO_UINT32 = math.MaxUint32 - 1 + +func TestMathMaxShouldCompile(t *testing.T) { + zero := uint64(SET_ZERO_UINT) + if zero != math.MaxUint64-1 { + t.Fatalf("zero: %v", zero) + } +}