aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-05-15 02:57:18 +0200
committerTeddy Wing2023-05-15 02:57:18 +0200
commit567f4e859ad48c9e2b01559f771cd20103c7903c (patch)
treed8a1248c47e568e255f492589896b0c3c3990ca6
parent73ca10c35a486a124548cd4141ed174683bc4fdb (diff)
downloadgocapturedrefrace-567f4e859ad48c9e2b01559f771cd20103c7903c.tar.bz2
Find out how to get closure arguments
-rw-r--r--gocapturedrefrace.go6
-rw-r--r--testdata/simple.go6
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)
}