aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-05-15 21:44:54 +0200
committerTeddy Wing2023-05-15 21:44:54 +0200
commita3515d6d5d52a84944b5bd0aaa863a50b3c1ec59 (patch)
treef93e0144b253d904f617fc19b0cf785b4760629f
parent0bd0a462ab4e733e62678d847b88a36ce95130f8 (diff)
downloadgocapturedrefrace-a3515d6d5d52a84944b5bd0aaa863a50b3c1ec59.tar.bz2
Add test for reference arguments
These should be reported as well, because they're shared references even though they're passed as arguments. This currently reports the variable name as "aStruct", will need to look into how to correct that.
-rw-r--r--gocapturedrefrace.go1
-rw-r--r--testdata/simple.go12
2 files changed, 13 insertions, 0 deletions
diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go
index f3e2e81..517cf8e 100644
--- a/gocapturedrefrace.go
+++ b/gocapturedrefrace.go
@@ -56,6 +56,7 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) {
formalParams = append(formalParams, field.Names[0].Obj)
}
fmt.Printf("%#v\n", formalParams)
+ // TODO: Ensure argument types are not references
// TODO: Build a list of variables created in the closure
assignments := assignmentsInFunc(pass, funcLit)
diff --git a/testdata/simple.go b/testdata/simple.go
index 0a2f0af..d01a95e 100644
--- a/testdata/simple.go
+++ b/testdata/simple.go
@@ -23,3 +23,15 @@ func main() {
strings.Repeat(str, 3)
}(copied)
}
+
+func argumentReference() {
+ type aStruct struct{
+ field int
+ }
+
+ s := aStruct{field: 0}
+
+ go func(s *aStruct) {
+ s.field += 1
+ }(&s)
+}