Skip to content

Commit

Permalink
change var mock to loose default
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Apr 8, 2024
1 parent fe2e2f3 commit c12e5a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.19"
const REVISION = "55018f6d640a578b197c4a03220e7a3122326f62+1"
const NUMBER = 168
const REVISION = "fe2e2f38793f24bda0a8690eedba01828ef79916+1"
const NUMBER = 169

func getRevision() string {
revSuffix := ""
Expand Down
32 changes: 12 additions & 20 deletions patch/syntax/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,17 @@ func (ctx *BlockContext) traverseNode(node syntax.Node, globaleNames map[string]
case *syntax.Field:
// ignore
default:
// unknown
if os.Getenv("XGO_DEBUG_VAR_TRAP_LOOSE") != "true" {
panic(fmt.Errorf("unrecognized node: %T", node))
}
errorUnknown("node", node)

}
return node
}
func errorUnknown(expectType string, node syntax.Node) {
// unknown
if os.Getenv("XGO_DEBUG_VAR_TRAP_STRICT") == "true" {
panic(fmt.Errorf("unrecognized %s: %T", expectType, node))
}
}

func (ctx *BlockContext) traverseStmt(node syntax.Stmt, globaleNames map[string]*DeclInfo, imports map[string]string) syntax.Stmt {
if node == nil {
Expand Down Expand Up @@ -251,10 +255,7 @@ func (ctx *BlockContext) traverseStmt(node syntax.Stmt, globaleNames map[string]
}
node.Results = ctx.traverseExpr(node.Results, globaleNames, imports)
default:
// unknown
if os.Getenv("XGO_DEBUG_VAR_TRAP_LOOSE") != "true" {
panic(fmt.Errorf("unrecognized stmt: %T", node))
}
errorUnknown("stmt", node)
}
return node
}
Expand Down Expand Up @@ -301,10 +302,7 @@ func (ctx *BlockContext) traverseSimpleStmt(node syntax.SimpleStmt, globaleNames
case *syntax.EmptyStmt:
// nothing
default:
// unknown
if os.Getenv("XGO_DEBUG_VAR_TRAP_LOOSE") != "true" {
panic(fmt.Errorf("unrecognized simple stmt: %T", node))
}
errorUnknown("simple stmt", node)
}
return node
}
Expand Down Expand Up @@ -505,10 +503,7 @@ func (ctx *BlockContext) traverseExpr(node syntax.Expr, globaleNames map[string]
}
case *syntax.BadExpr:
default:
// unknown
if os.Getenv("XGO_DEBUG_VAR_TRAP_LOOSE") != "true" {
panic(fmt.Errorf("unrecognized expr: %T", node))
}
errorUnknown("expr", node)
}
return node
}
Expand Down Expand Up @@ -569,10 +564,7 @@ func (ctx *BlockContext) traverseDecl(node syntax.Decl, globaleNames map[string]
node.Values = ctx.traverseExpr(node.Values, globaleNames, imports)
}
default:
// unknown
if os.Getenv("XGO_DEBUG_VAR_TRAP_LOOSE") != "true" {
panic(fmt.Errorf("unrecognized stmt: %T", node))
}
errorUnknown("stmt", node)
}
return node
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.19"
const REVISION = "55018f6d640a578b197c4a03220e7a3122326f62+1"
const NUMBER = 168
const REVISION = "fe2e2f38793f24bda0a8690eedba01828ef79916+1"
const NUMBER = 169

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
4 changes: 2 additions & 2 deletions runtime/mock/MOCK_VAR_CONST.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestPatchVarTest(t *testing.T) {

```

Check [../test/patch_const/patch_var_test.go](../test/patch_const/patch_var_test.go) for more cases.
Check [../test/patch/patch_var_test.go](../test/patch/patch_var_test.go) for more cases.

## `PatchByName` on constant
```go
Expand All @@ -46,7 +46,7 @@ import (

const N = 50

func TestPatchInElseShouldWork(t *testing.T) {
func TestPatchConst(t *testing.T) {
mock.PatchByName("github.com/xhd2015/xgo/runtime/test/patch_const", "N", func() int {
return 5
})
Expand Down

0 comments on commit c12e5a6

Please sign in to comment.