From 89e483b8eca1011abdc1424f1358b581d8033c38 Mon Sep 17 00:00:00 2001 From: xgopilot Date: Mon, 27 Oct 2025 10:34:53 +0000 Subject: [PATCH] test(demo): add regression demos for issue #1370 cases - case1: go/types.Object with Scope.Insert() calling private setParent() - case2: go/ast.Expr interface conversion with private exprNode() Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- _demo/go/issue1370_case1/main.go | 18 ++++++++++++++++++ _demo/go/issue1370_case2/main.go | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 _demo/go/issue1370_case1/main.go create mode 100644 _demo/go/issue1370_case2/main.go diff --git a/_demo/go/issue1370_case1/main.go b/_demo/go/issue1370_case1/main.go new file mode 100644 index 00000000..bac77c8e --- /dev/null +++ b/_demo/go/issue1370_case1/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "go/types" +) + +func main() { + scope := types.NewScope(nil, 0, 0, "test") + obj := types.NewVar(0, nil, "x", types.Typ[types.Int]) + + scope.Insert(obj) + + if scope.Lookup("x") == obj { + println("SUCCESS: Scope.Insert and Lookup work correctly") + } else { + println("FAIL: Lookup returned wrong object") + } +} diff --git a/_demo/go/issue1370_case2/main.go b/_demo/go/issue1370_case2/main.go new file mode 100644 index 00000000..214541bd --- /dev/null +++ b/_demo/go/issue1370_case2/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "go/ast" + "go/token" +) + +func main() { + // Create an identifier node + ident := &ast.Ident{ + NamePos: token.Pos(1), + Name: "foo", + } + + // Convert to ast.Expr interface + // The ast.Expr interface has a private method exprNode() + // Before the fix, this interface conversion would cause segfaults + // when calling methods because the PkgPath was incorrectly set + var expr ast.Expr = ident + + // Call methods on the interface + fmt.Printf("Identifier: %s\n", ident.Name) + fmt.Printf("Position: %d\n", expr.Pos()) + + println("SUCCESS: ast.Expr interface conversion works correctly") +}