diff options
author | Teddy Wing | 2023-05-15 02:57:18 +0200 |
---|---|---|
committer | Teddy Wing | 2023-05-15 02:57:18 +0200 |
commit | 567f4e859ad48c9e2b01559f771cd20103c7903c (patch) | |
tree | d8a1248c47e568e255f492589896b0c3c3990ca6 | |
parent | 73ca10c35a486a124548cd4141ed174683bc4fdb (diff) | |
download | gocapturedrefrace-567f4e859ad48c9e2b01559f771cd20103c7903c.tar.bz2 |
Find out how to get closure arguments
-rw-r--r-- | gocapturedrefrace.go | 6 | ||||
-rw-r--r-- | testdata/simple.go | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index 1e00d21..9544d48 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -51,6 +51,12 @@ func run(pass *analysis.Pass) (interface{}, error) { } func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) { + fmt.Print("Params: ") + for _, field := range funcLit.Type.Params.List { + fmt.Printf("%#v, ", field.Names[0].Name) + } + fmt.Println() + ast.Inspect( funcLit, func(node ast.Node) bool { diff --git a/testdata/simple.go b/testdata/simple.go index 694bd33..0a2f0af 100644 --- a/testdata/simple.go +++ b/testdata/simple.go @@ -5,10 +5,12 @@ import "strings" func main() { capturedReference := 0 capturedReference2 := 1 + copied := 0 - go func() { + go func(copied int) { capturedReference += 1 capturedReference2 += 1 + copied += 1 if capturedReference == 1 { return @@ -19,5 +21,5 @@ func main() { str := "a" strings.Repeat(str, 3) - }() + }(copied) } |