From ad4b4956a5ac8d08b271417687e354e5c66491a8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 16 May 2023 21:05:21 +0200 Subject: Report reference-type closure arguments --- gocapturedrefrace.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'gocapturedrefrace.go') diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 50a0297..c3d5d82 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -69,13 +69,22 @@ func run(pass *analysis.Pass) (interface{}, error) { fmt.Printf("funcLit params: %#v\n", funcLit.Type.Params.List) for _, arg := range funcLit.Type.Params.List { - fmt.Printf("funcLit param:") - - for _, argNameIdent := range arg.Names { - fmt.Printf("%#v, ", argNameIdent.Name) + fmt.Printf( + "funcLit param: %s ; type: %#v\n", + arg.Names[0].Name, + arg.Type, + ) + + _, ok := arg.Type.(*ast.StarExpr) + if !ok { + continue } - fmt.Println() + pass.Reportf( + arg.Pos(), + "reference %s in goroutine closure", + arg.Names[0], + ) } // scope := pass.TypesInfo.Scopes[funcLit] -- cgit v1.2.3