aboutsummaryrefslogtreecommitdiffstats
path: root/gocapturedrefrace.go
diff options
context:
space:
mode:
Diffstat (limited to 'gocapturedrefrace.go')
-rw-r--r--gocapturedrefrace.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go
index 11f2ac1..3ac8022 100644
--- a/gocapturedrefrace.go
+++ b/gocapturedrefrace.go
@@ -58,6 +58,8 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) {
fmt.Printf("%#v\n", formalParams)
// TODO: Build a list of variables created in the closure
+ assignments := assignmentsInFunc(pass, funcLit)
+ fmt.Printf("%#v\n", assignments)
ast.Inspect(
funcLit,
@@ -90,3 +92,35 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) {
},
)
}
+
+func assignmentsInFunc(
+ pass *analysis.Pass,
+ funcLit *ast.FuncLit,
+) []string {
+ assignments := []string{}
+
+ ast.Inspect(
+ funcLit,
+ func(node ast.Node) bool {
+ ident, ok := node.(*ast.Ident)
+ if !ok {
+ return true
+ }
+
+ if ident.Obj == nil || ident.Obj.Decl == nil {
+ return true
+ }
+
+ _, ok = ident.Obj.Decl.(*ast.AssignStmt)
+ if !ok {
+ return true
+ }
+
+ assignments = append(assignments, ident.Name)
+
+ return true
+ },
+ )
+
+ return assignments
+}