aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-05-17 19:51:29 +0200
committerTeddy Wing2023-05-17 19:51:29 +0200
commit4054b6fdd71811304e4bc7af8c8799becc5338a0 (patch)
tree920b77205acdbc8e2ccd76d74e96f5ca9ad617a2
parent52dbd96539f74b180c11c7ed1e2c83ed49c3f8bc (diff)
downloadgocapturedrefrace-4054b6fdd71811304e4bc7af8c8799becc5338a0.tar.bz2
Ignore captured variables containing functions
-rw-r--r--gocapturedrefrace.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go
index e44b397..66be1e9 100644
--- a/gocapturedrefrace.go
+++ b/gocapturedrefrace.go
@@ -16,7 +16,6 @@
// along with Gocapturedrefrace. If not, see
// <https://www.gnu.org/licenses/>.
-
// TODO: package documentation.
package gocapturedrefrace
@@ -52,8 +51,6 @@ func run(pass *analysis.Pass) (interface{}, error) {
// Inspect closure argument list.
for _, arg := range funcLit.Type.Params.List {
- // TODO: Ignore closures passed as arguments.
-
// Report reference arguments.
_, ok := arg.Type.(*ast.StarExpr)
if !ok {
@@ -104,15 +101,20 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) {
}
// Ignore non-variable identifiers.
- _, ok = scopeObj.(*types.Var)
+ variable, ok := scopeObj.(*types.Var)
if !ok {
return true
}
+ // Ignore captured callable variables, like function arguments.
+ _, isVariableTypeSignature := variable.Type().(*types.Signature)
+
// TODO: Ignore shadowing variables.
// Identifier was defined in a different scope.
- if funcScope != scope {
+ if funcScope != scope &&
+ !isVariableTypeSignature {
+
pass.Reportf(
ident.Pos(),
"captured reference %s in goroutine closure",