aboutsummaryrefslogtreecommitdiffstats
path: root/testdata/simple.go
blob: 772b58c9dc79bd964ed3cce307931136db03fcc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import "strings"

func main() {
	capturedReference := 0
	capturedReference2 := 1
	copied := 0

	go func(copied int) {
		capturedReference += 1 // want "captured reference capturedReference in goroutine closure"
		capturedReference2 += 1 // want "captured reference capturedReference2 in goroutine closure"
		copied += 1

		if capturedReference == 1 { // want "captured reference capturedReference in goroutine closure"
			return
		}

		newVar := 0
		newVar += 1

		str := "a"
		strings.Repeat(str, 3)

		var decl string
		decl = "b"
		strings.Repeat(decl, 2)
	}(copied)
}

func argumentReference() {
	type aStruct struct{
		field int
	}

	s := aStruct{field: 0}

	go func(s *aStruct) { // want "reference s in goroutine closure"
		s.field += 1
	}(&s)
}