diff options
author | Teddy Wing | 2023-05-16 03:03:30 +0200 |
---|---|---|
committer | Teddy Wing | 2023-05-16 03:03:30 +0200 |
commit | 25ca092939a76031e531ace87a457bbe9b29066d (patch) | |
tree | ba4dbc4972d836255ea95dec3d42d78c7b99191d | |
parent | c5a5153e6abfffbedc55e24ec505b1420660b5e3 (diff) | |
download | gocapturedrefrace-25ca092939a76031e531ace87a457bbe9b29066d.tar.bz2 |
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.
-rw-r--r-- | gocapturedrefrace.go | 4 |
1 files changed, 3 insertions, 1 deletions
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) |