diff options
author | Teddy Wing | 2023-05-19 20:18:25 +0200 |
---|---|---|
committer | Teddy Wing | 2023-05-19 20:18:25 +0200 |
commit | 47060dea4ac14437ee0f67dabdb1375cb3e19e2d (patch) | |
tree | 2d495d3f69f6e03c39755537a43549ad9e16b7d5 | |
parent | 3cb707eb5eaf9983ca22b40b87e704bd93c75e71 (diff) | |
download | gocapturedrefrace-47060dea4ac14437ee0f67dabdb1375cb3e19e2d.tar.bz2 |
Inspect `go` statement call function to try to find local closures
-rw-r--r-- | capturedrefrace.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/capturedrefrace.go b/capturedrefrace.go index e7d0c45..afb104c 100644 --- a/capturedrefrace.go +++ b/capturedrefrace.go @@ -51,6 +51,7 @@ package capturedrefrace import ( + "fmt" "go/ast" "go/token" "go/types" @@ -83,6 +84,18 @@ func run(pass *analysis.Pass) (interface{}, error) { return } + fmt.Printf("func: %#v\n", goStmt.Call.Fun) + funcIdent, ok := goStmt.Call.Fun.(*ast.Ident) + if ok { + fmt.Printf("funcobj: %#v\n", funcIdent.Obj) + t := pass.TypesInfo.Types[funcIdent] + fmt.Printf("functype-fromtypesinfo: %#v\n", t) + fmt.Printf("funcdecl: %#v\n", funcIdent.Obj.Decl) + obj := pass.TypesInfo.Uses[funcIdent] + fmt.Printf("funcobj-fromtypesinfo: %#v\n", obj) + fmt.Printf("funcobj-fromtypesinfo-type: %#v\n", obj.Type()) + } + // Look for a function literal after the `go` statement. funcLit, ok := goStmt.Call.Fun.(*ast.FuncLit) if !ok { |