This is a follow-up for https://golang.org/cl/24340.
Updates #14664.
Fixes #18374.
Change-Id: I2831556a9014d30ec70d5f91943d18c33db5b390
Reviewed-on: https://go-review.googlesource.com/34630
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
// checkCopyLocksCallExpr detects lock copy in the arguments to a function call
func checkCopyLocksCallExpr(f *File, ce *ast.CallExpr) {
- if id, ok := ce.Fun.(*ast.Ident); ok && id.Name == "new" && f.pkg.types[id].IsBuiltin() {
- // Skip 'new(Type)' for built-in 'new'
- return
+ if id, ok := ce.Fun.(*ast.Ident); ok && f.pkg.types[id].IsBuiltin() {
+ switch id.Name {
+ case "new", "len", "cap":
+ return
+ }
}
for _, x := range ce.Args {
if path := lockPathRhs(f, x); path != nil {
fmuSlice := fmuA[:] // OK
}
+func LenAndCapOnLockArrays() {
+ var a [5]sync.Mutex
+ aLen := len(a) // OK
+ aCap := cap(a) // OK
+
+ // override 'len' and 'cap' keywords
+
+ len := func(interface{}) {}
+ len(a) // ERROR "function call copies lock value: sync.Mutex"
+
+ cap := func(interface{}) {}
+ cap(a) // ERROR "function call copies lock value: sync.Mutex"
+}
+
// SyncTypesCheck checks copying of sync.* types except sync.Mutex
func SyncTypesCheck() {
// sync.RWMutex copying