diff options
| author | Teddy Wing | 2023-05-16 21:05:21 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2023-05-16 21:05:21 +0200 | 
| commit | ad4b4956a5ac8d08b271417687e354e5c66491a8 (patch) | |
| tree | 8c551290d37768325add0f30345046a90a1291ed | |
| parent | 2c3cbc5822e19a000b23a959ff70dd57be7757e2 (diff) | |
| download | gocapturedrefrace-ad4b4956a5ac8d08b271417687e354e5c66491a8.tar.bz2 | |
Report reference-type closure arguments
| -rw-r--r-- | gocapturedrefrace.go | 19 | ||||
| -rw-r--r-- | testdata/simple.go | 4 | 
2 files changed, 16 insertions, 7 deletions
| 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] diff --git a/testdata/simple.go b/testdata/simple.go index 9fdf7a5..772b58c 100644 --- a/testdata/simple.go +++ b/testdata/simple.go @@ -35,7 +35,7 @@ func argumentReference() {  	s := aStruct{field: 0} -	go func(s *aStruct) { -		s.field += 1 // want "reference s in goroutine closure" +	go func(s *aStruct) { // want "reference s in goroutine closure" +		s.field += 1  	}(&s)  } | 
