From 816854c9cc4277b3ab30fac9963440bf63bbb032 Mon Sep 17 00:00:00 2001 From: xgopilot Date: Thu, 23 Oct 2025 10:44:56 +0000 Subject: [PATCH] test(demo): add go/types Scope.Insert demo Add a demo program to demonstrate the fix for cross-package interface private method calls. This demo uses go/types.Scope.Insert which has private methods in the go/types package, making it a good test case for the bug fix in PR #1371. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang --- _demo/go/gotypesissue/main.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 _demo/go/gotypesissue/main.go diff --git a/_demo/go/gotypesissue/main.go b/_demo/go/gotypesissue/main.go new file mode 100644 index 00000000..58a66b45 --- /dev/null +++ b/_demo/go/gotypesissue/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "go/token" + "go/types" +) + +func main() { + pkg := types.NewPackage("example", "example") + scope := pkg.Scope() + + obj := types.NewVar(token.NoPos, pkg, "testVar", types.Typ[types.Int]) + + insertedObj := scope.Insert(obj) + if insertedObj != nil { + println("ERROR: Variable already exists in scope") + return + } + + lookup := scope.Lookup("testVar") + if lookup == nil { + println("ERROR: Failed to lookup variable") + return + } + + if lookup.Name() != "testVar" { + println("ERROR: Wrong variable name") + return + } + + println("SUCCESS: Scope.Insert and Lookup work correctly") +}