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") +}