Skip to content

Commit 29d11ef

Browse files
Manishearthrobpike
authored andcommitted
cmd/vet: add test that copylock catches copying a sync.Map
fixes #21635 Change-Id: I78716d47b6a930074e5394f7171d5f545dfba0bc Reviewed-on: https://go-review.googlesource.com/59690 Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Rob Pike <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent ce54a0c commit 29d11ef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/cmd/vet/testdata/copylock_func.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import "sync"
1111

1212
func OkFunc(*sync.Mutex) {}
1313
func BadFunc(sync.Mutex) {} // ERROR "BadFunc passes lock by value: sync.Mutex"
14+
func BadFunc2(sync.Map) {} // ERROR "BadFunc2 passes lock by value: sync.Map contains sync.Mutex"
1415
func OkRet() *sync.Mutex {}
1516
func BadRet() sync.Mutex {} // Don't warn about results
1617

1718
var (
18-
OkClosure = func(*sync.Mutex) {}
19-
BadClosure = func(sync.Mutex) {} // ERROR "func passes lock by value: sync.Mutex"
19+
OkClosure = func(*sync.Mutex) {}
20+
BadClosure = func(sync.Mutex) {} // ERROR "func passes lock by value: sync.Mutex"
21+
BadClosure2 = func(sync.Map) {} // ERROR "func passes lock by value: sync.Map contains sync.Mutex"
2022
)
2123

2224
type EmbeddedRWMutex struct {

0 commit comments

Comments
 (0)