diff options
Diffstat (limited to 'gocapturedrefrace.go')
-rw-r--r-- | gocapturedrefrace.go | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 762473b..21a0d16 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -2,6 +2,7 @@ package gocapturedrefrace import ( "bytes" + "fmt" "go/ast" "go/printer" @@ -30,11 +31,16 @@ func run(pass *analysis.Pass) (interface{}, error) { panic(err) } - pass.Reportf( - goStmt.Pos(), - "go statement found %q", - printedNode, - ) + fmt.Printf("%#v\n", goStmt) + + // TODO: Get func literal of go statement + // TODO: Get variables in func literal + funcLit, ok := goStmt.Call.Fun.(*ast.FuncLit) + if !ok { + return true + } + + checkClosure(pass, funcLit) return true }, @@ -43,3 +49,23 @@ func run(pass *analysis.Pass) (interface{}, error) { return nil, nil } + +func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) { + ast.Inspect( + funcLit, + func(node ast.Node) bool { + variable, ok := node.(*ast.Ident) + if !ok { + return true + } + + pass.Reportf( + variable.Pos(), + "variable found %q", + variable, + ) + + return true + }, + ) +} |