aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-05-19 20:18:25 +0200
committerTeddy Wing2023-05-19 20:18:25 +0200
commit47060dea4ac14437ee0f67dabdb1375cb3e19e2d (patch)
tree2d495d3f69f6e03c39755537a43549ad9e16b7d5
parent3cb707eb5eaf9983ca22b40b87e704bd93c75e71 (diff)
downloadgocapturedrefrace-47060dea4ac14437ee0f67dabdb1375cb3e19e2d.tar.bz2
Inspect `go` statement call function to try to find local closures
-rw-r--r--capturedrefrace.go13
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 {