From 939b3aad88ce3043906d95329fecd8302ea3d9d7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 17 May 2023 20:57:05 +0200 Subject: Separate `isVariableTypeSignature` condition It doesn't need to be attached to the `funcScope` condition as it's a separate check. Wasn't thinking carefully when I added the check. --- gocapturedrefrace.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 66be1e9..ff5ac9a 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -26,6 +26,8 @@ import ( "golang.org/x/tools/go/analysis" ) +var version = "0.0.1" + var Analyzer = &analysis.Analyzer{ Name: "gocapturedrefrace", Doc: "reports captured references in goroutine closures", @@ -108,13 +110,14 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) { // Ignore captured callable variables, like function arguments. _, isVariableTypeSignature := variable.Type().(*types.Signature) + if isVariableTypeSignature { + return true + } // TODO: Ignore shadowing variables. // Identifier was defined in a different scope. - if funcScope != scope && - !isVariableTypeSignature { - + if funcScope != scope { pass.Reportf( ident.Pos(), "captured reference %s in goroutine closure", -- cgit v1.2.3