aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-05-20 02:08:44 +0200
committerTeddy Wing2023-05-20 02:08:44 +0200
commit266552a2e1b202b2aadb7b6105e07afdd681ef5c (patch)
tree011ab86d28dcdd458856403f6250a975407ed252
parent47060dea4ac14437ee0f67dabdb1375cb3e19e2d (diff)
downloadgocapturedrefrace-266552a2e1b202b2aadb7b6105e07afdd681ef5c.tar.bz2
Find `*ast.FuncLit` in local assignment
Get the FuncLit from the rhs of the local variable.
-rw-r--r--capturedrefrace.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/capturedrefrace.go b/capturedrefrace.go
index afb104c..54c5c04 100644
--- a/capturedrefrace.go
+++ b/capturedrefrace.go
@@ -94,6 +94,26 @@ func run(pass *analysis.Pass) (interface{}, error) {
obj := pass.TypesInfo.Uses[funcIdent]
fmt.Printf("funcobj-fromtypesinfo: %#v\n", obj)
fmt.Printf("funcobj-fromtypesinfo-type: %#v\n", obj.Type())
+ def := pass.TypesInfo.Defs[funcIdent]
+ fmt.Printf("func def: %#v\n", def)
+
+ obj2 := pass.TypesInfo.ObjectOf(funcIdent)
+ fmt.Printf("obj2: %#v\n", obj2)
+
+ fmt.Printf("obj-parent: %#v\n", obj.Parent())
+
+ fmt.Printf("parent lookup: %#v\n", obj.Parent().Lookup(obj.Name()))
+ // TODO: How to get the scope of the closure?
+
+ das, ok := funcIdent.Obj.Decl.(*ast.AssignStmt)
+ if ok {
+ for _, expr := range das.Rhs {
+ fl, ok := expr.(*ast.FuncLit)
+ if ok {
+ fmt.Printf("funclit: %#v\n", fl)
+ }
+ }
+ }
}
// Look for a function literal after the `go` statement.