From 25ca092939a76031e531ace87a457bbe9b29066d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 16 May 2023 03:03:30 +0200 Subject: Find a `pass.TypesInfo.Scopes[]` that's not nil If I had read the comment for `Scopes` in https://godocs.io/go/types#Info I would have known that only a subset of `ast.Node` can appear in the `Scopes` field. Tried ones until I ended up with valid scopes. Now that we have a valid scope, maybe we can find out if it's using variables not declared within that scope. --- gocapturedrefrace.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 4187918..d8fc4ef 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -57,7 +57,9 @@ func run(pass *analysis.Pass) (interface{}, error) { } // scope := pass.TypesInfo.Scopes[funcLit] - scope := pass.TypesInfo.Scopes[goStmt] + // scope := pass.TypesInfo.Scopes[goStmt] + // scope := pass.TypesInfo.Scopes[funcLit.Body] + scope := pass.TypesInfo.Scopes[funcLit.Type] fmt.Println("scope:", scope) checkClosure(pass, funcLit) -- cgit v1.2.3