diff options
author | Teddy Wing | 2023-05-16 20:44:34 +0200 |
---|---|---|
committer | Teddy Wing | 2023-05-16 20:45:04 +0200 |
commit | 9a15014411a93d47b7056248754cde43aaf19382 (patch) | |
tree | 6bc340b3482d9318ee188a9a25b7a084d14e0e28 | |
parent | 21373e26ed585b0b7cbc29f31b71744ce6409934 (diff) | |
download | gocapturedrefrace-9a15014411a93d47b7056248754cde43aaf19382.tar.bz2 |
Try to get the arguments of the closure from `goStmt.Call.Args`
-rw-r--r-- | gocapturedrefrace.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 3174a09..de3bf10 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -34,6 +34,17 @@ func run(pass *analysis.Pass) (interface{}, error) { } fmt.Printf("%#v\n", goStmt) + fmt.Printf("closure arguments: %#v\n", goStmt.Call.Args) + + for _, arg := range goStmt.Call.Args { + argIdent, ok := arg.(*ast.Ident) + if !ok { + return true + } + + fmt.Printf("argIdent: %s: %#v\n", argIdent.Name, argIdent.Obj) + // Doesn't include `(s *aStruct)` which is a `*ast.UnaryExpr`, not a `*ast.Ident`. + } // TODO: How to get types.Func or {ast,types}.Scope of function literal? funcIdent, ok := goStmt.Call.Fun.(*ast.Ident) |