]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: include function name or value in copylock message
authorRob Pike <r@golang.org>
Sat, 24 Dec 2016 21:51:21 +0000 (08:51 +1100)
committerRob Pike <r@golang.org>
Tue, 3 Jan 2017 19:23:23 +0000 (19:23 +0000)
Given
var t struct{ lock sync.Mutex }
var fntab []func(t)
f(a(), b(&t), c(), fntab[0](t))

Before:
function call copies lock value: struct{lock sync.Mutex} contains sync.Mutex

After:
call of fntab[0] copies lock value: struct{lock sync.Mutex} contains sync.Mutex

This will make diagnosis easier when there are multiple function calls per line.

Change-Id: I9881713c5671b847b84a0df0115f57e7cba17d72
Reviewed-on: https://go-review.googlesource.com/34730
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/vet/copylock.go
src/cmd/vet/testdata/copylock.go
src/cmd/vet/testdata/copylock_func.go

index f3ab8e2e055306d4bbe641559b662e711f3d5848..27eb5d465174dd7a75a477d4386fdd7bf6156176 100644 (file)
@@ -101,7 +101,7 @@ func checkCopyLocksCallExpr(f *File, ce *ast.CallExpr) {
        }
        for _, x := range ce.Args {
                if path := lockPathRhs(f, x); path != nil {
-                       f.Badf(x.Pos(), "function call copies lock value: %v", path)
+                       f.Badf(x.Pos(), "call of %s copies lock value: %v", f.gofmt(ce.Fun), path)
                }
        }
 }
index 3ce06f88d421af7253f2c8cafada9de519d9ff4a..6fabbc337a0d6ac5865ca7fc8684551ac0ab4a7f 100644 (file)
@@ -67,7 +67,7 @@ func BadFunc() {
 
        // override 'new' keyword
        new := func(interface{}) {}
-       new(t) // ERROR "function call copies lock value: testdata.Tlock contains sync.Once contains sync.Mutex"
+       new(t) // ERROR "call of new copies lock value: testdata.Tlock contains sync.Once contains sync.Mutex"
 
        // copy of array of locks
        var muA [5]sync.Mutex
@@ -96,10 +96,10 @@ func LenAndCapOnLockArrays() {
        // override 'len' and 'cap' keywords
 
        len := func(interface{}) {}
-       len(a) // ERROR "function call copies lock value: sync.Mutex"
+       len(a) // ERROR "call of len copies lock value: sync.Mutex"
 
        cap := func(interface{}) {}
-       cap(a) // ERROR "function call copies lock value: sync.Mutex"
+       cap(a) // ERROR "call of cap copies lock value: sync.Mutex"
 }
 
 // SyncTypesCheck checks copying of sync.* types except sync.Mutex
index bfafa124fabb5feeeeef45015e28796dfb0795fb..d51ff27cda04fde453b16bd925bf91bed7fae0f5 100644 (file)
@@ -86,8 +86,10 @@ func FuncCallInterfaceArg(f func(a int, b interface{})) {
        f(1, "foo")
        f(2, &t)
        f(3, &sync.Mutex{})
-       f(4, m) // ERROR "function call copies lock value: sync.Mutex"
-       f(5, t) // ERROR "function call copies lock value: struct{lock sync.Mutex} contains sync.Mutex"
+       f(4, m) // ERROR "call of f copies lock value: sync.Mutex"
+       f(5, t) // ERROR "call of f copies lock value: struct{lock sync.Mutex} contains sync.Mutex"
+       var fntab []func(t)
+       fntab[0](t) // ERROR "call of fntab.0. copies lock value: struct{lock sync.Mutex} contains sync.Mutex"
 }
 
 // Returning lock via interface value