diff options
author | Teddy Wing | 2023-05-16 21:37:32 +0200 |
---|---|---|
committer | Teddy Wing | 2023-05-16 21:37:32 +0200 |
commit | e90bf2432617a5fca20f2b9fc6332fc0d2bc6979 (patch) | |
tree | 3fa5ce1dee7c37edbc25ff788d996e2bb1886639 | |
parent | 79f8de910e6ec7fbb123945385789f19091e0a07 (diff) | |
download | gocapturedrefrace-e90bf2432617a5fca20f2b9fc6332fc0d2bc6979.tar.bz2 |
run: Add a few explanatory comments
-rw-r--r-- | gocapturedrefrace.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 6d560a1..c4678a3 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -20,18 +20,21 @@ func run(pass *analysis.Pass) (interface{}, error) { ast.Inspect( file, func(node ast.Node) bool { + // Find `go` statements. goStmt, ok := node.(*ast.GoStmt) if !ok { return true } + // Look for a function literal after the `go` statement. funcLit, ok := goStmt.Call.Fun.(*ast.FuncLit) if !ok { return true } + // Inspect closure argument list. for _, arg := range funcLit.Type.Params.List { - // TODO: Explain + // Report reference arguments. _, ok := arg.Type.(*ast.StarExpr) if !ok { continue @@ -44,6 +47,7 @@ func run(pass *analysis.Pass) (interface{}, error) { ) } + // Get the closure's scope. funcScope := pass.TypesInfo.Scopes[funcLit.Type] checkClosure(pass, funcLit, funcScope) |