aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-05-16 20:52:14 +0200
committerTeddy Wing2023-05-16 20:52:14 +0200
commit2c3cbc5822e19a000b23a959ff70dd57be7757e2 (patch)
tree076a1877f00ccf5f1d16360c9595bad48916bf55
parent9a15014411a93d47b7056248754cde43aaf19382 (diff)
downloadgocapturedrefrace-2c3cbc5822e19a000b23a959ff70dd57be7757e2.tar.bz2
Get arguments of closure with `funcLit.Type.Params.List`
Easier to use than `goStmt.Call.Args` because we don't have to handle both `*ast.Expr` and `*ast.UnaryExpr`.
-rw-r--r--gocapturedrefrace.go29
1 files changed, 20 insertions, 9 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go
index de3bf10..50a0297 100644
--- a/gocapturedrefrace.go
+++ b/gocapturedrefrace.go
@@ -36,15 +36,15 @@ 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`.
- }
+ // 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)
@@ -67,6 +67,17 @@ func run(pass *analysis.Pass) (interface{}, error) {
return true
}
+ fmt.Printf("funcLit params: %#v\n", funcLit.Type.Params.List)
+ for _, arg := range funcLit.Type.Params.List {
+ fmt.Printf("funcLit param:")
+
+ for _, argNameIdent := range arg.Names {
+ fmt.Printf("%#v, ", argNameIdent.Name)
+ }
+
+ fmt.Println()
+ }
+
// scope := pass.TypesInfo.Scopes[funcLit]
// scope := pass.TypesInfo.Scopes[goStmt]
// scope := pass.TypesInfo.Scopes[funcLit.Body]