Commit d698e614 authored by Rob Pike's avatar Rob Pike

cmd/vet: include function name or value in copylock message

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/34730Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 161cd34f
......@@ -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)
}
}
}
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment